(navigation image)
Home American Libraries | Canadian Libraries | Universal Library | Community Texts | Project Gutenberg | Biodiversity Heritage Library | Children's Library | Additional Collections
Search: Advanced Search
Anonymous User (login or join us)
Upload
See other formats

Full text of "VIC-1541 Single Drive Floppy Disk User's Manual (1981-09)(Commodore)"

VIC 1541 



INGL 

USER'S MANUAL 




Cz commodore 

COMPUTER 



VIC-1541 

SINGLE DRIVE FLOPPY DISK 

USER'S MANUAL 



P/N 1540031-02 



Cx commodore 

COMPUTER 



WARNING: This equipment has been certified to comply with the limits for a 
Class B computing ievice, pursuant to Subpart J of Part 15 of FCC Rules. Only 
computers certified to comply with the Class B limits may be attached to this 
printer. Operation with noncertified computers is likely to result in interference 
to radio and TV reception," 

This warning is valid for the equipment which has the fallowing FCC label 
on its rear. 



CERTIFIED TO COMPLY WITH CLASS B LIMITS. 

PART 15 OF F^C RULES SEE INSTRUCTIONS IF 
INTERFERENCE TO RADIO RECEPTION IS SUS- 
PECTED. 



The information in this: manual has been reviewed and is bslieved to be entirely 
reliable. No responsibility, however, is assumed for inaccuracies. The material in 
this manna": is for information purposes only, and is subject to change without 
notice. 



©Commodore Business Machines, Inc., September 1981 
"All rights reserved." 



Table of Contents Page 

1 . General Description 3 

2. Unpacking and Connecting 6 

Contents of Box 6 

Connection of Cables ,,,,,,.,,. 7 

Powering On , 7 

Insertion of Diskette S 

Using with VIC20 or Commodore 64 $ 

3. Using Programs . > * 

Loading Pie-packaged Software 9 

LOAD 9 

Directory of Disk , 9 

Pattern Matching & Wild Cards 11 

SAVE • ■ 12 

5AVE and replace ,.,,,,... 13 

VERIFY , 13 

DOS Support Program 14 

4. Disk Commands .... . - 14 

OPEN AND PRINT # 14 

NEW - 15 

COPY 16 

RENAME 16 

SCRATCH 17 

INITIALIZE 17 

VALIDATE 17 

DUPLICATE 18 

Reading the Error CliaMiel 18 

CLOSE 18 

5. Sequential Files . 19 

OPEN 19 

PRINT #and INPUT # 20 

GET* 22 

Reading the Directory 23 

6. Random Files ■ ■ ... 26 

Opening a channel for random access data 27 

BLOCK-READ 17 

BLOCK-WRITE 28 

BLOCK-ALLOCATE 29 

BLOCK-FREE 19 

BUFFER-POINTER 31 

USER1 and USER2 32 



7, Relative Files ■ 33 

Creating a relative file 34 

Using relative files 35 

8, Programming the Disk Controller . . 37 

BLOCK-EXECUTE 37 

MEMORY-READ 37 

MEMORY-WRITE 38 

MEMORY-EXECUTE 38 

USER Commands 39 

9, Changing the Disk Device Number 39 

Software Method 39 

Hardware Method , 40 

Appendices 

A. Disk Command Summary . 41 

B. Error Messages 42 

C. Demonstration Disk Programs 47 

D. Disk Formats Tables 54 






]. GENERAL DESCRIPTION 

Introduction 

Welcome to the fastest. eas;est. and most efficient Rung system available 
for youi Commodore d4 or VIC 20 compute;, youi 1541 DISK DRIVE, This 
ritaAttal Ixat been designed to allow you how to get the most from your drive, 
whether you'ie a beginner or an advanced professional. 

If you are a beginner, the first few chapters will help you through the 
basics of disk drive installation and operation. As your skill and programming 
knowledge improves, you will find mure uses for your disk drive and the more 
advanced chapters of l Li is. manual will become much more valuable. 

If you're e professional this reference guide will show you how to put the 
1541 through its pates to perform iusl about all iJie disk drivs jobs you can 

tninkof. 

No matter what level of expertise you have, your 1541 disk drive will 
dramatically improve the overall capabilities of yojr computer system. 

Before you est to the details of 1541 operation, you should he aware of a 
few important points This manual is a RFFF.RFACF. GlIIDF, which means that 
unless the information you seeV directly pertains to the disk ur disk drive you 
will have to use your Commander 64 or VIC 20 User's Guides and Programmer's 
Reference Guides to fine p-ogramr'iing information. In addition, even though we 
give you step-by-stap instructions for each operation, you should become 
familisr with BASIC and the instructions ("called commands) that help you 
operate your disks and drives. However, if you just want to use your disk drive 
unit to load and save prepackaged software, we've included an easy and brief 
section on doingjust that. 

Now , , . let's get on wiili the general infonnatiun. 

The commands for the disk drive come in several ievels of sophis.cation. 
Starting in chapter three, you can learn how the commands that atlew you to 
save and loac programs with the disk work. Chapter lour teaches you hew 
commands arc sent to the disk, and iiuoducjs the disk maintenance commands. 

Chapter five tells you how to work with sequential data lies. These are 
very' similar to their counterparts or. tape (but much faster). Chapter six 
introduces the commands that allow you to work with random files, access any 
piece of data on the disk, and how you oigani2e the diskette into tracks and 
blocks Chapter seuerl describes the special relative files Relative files are the 
best melhcd of storing data bases, especially when they are used along with 
sequential files. 

Chapter e.ght describes methods For programming the disk controller 
circuits at the machine language level. And the flnul chapter shows you how to 



change the disk device number, by "cutting" a line inside the drive unit or 
through software. 

Remember, you don't really need to leant every Ihiug in this Dook all a: 
once. The first four chapters are enough to get yua going, and the next couple 
are enough foi most opetalion:i. Getting to know your disk drive will reward you 
in many ways speed ofupcration, reliability, and much more flexibility in your 
Jata processing capabilities. 

Specifications 

This disk drive allows you to store up to 144 different programs and/or 
data files on a single minifloppy diskette, for a maximum of over 174,030 bytes 
worth of information storage. 

Included in the drive is circuitry for both the disk controller and a 
complete disk operating system, a total of 16K of ROM arid 2K of RAM 
memory, This circuitry makes your Commodore 1 541 disk drive an "intelligent" 
device. This means it dtaes its own processing without taking any memory away 
from your Commodore &4 or VIC 20 computer. The disk uses a "pipeline" 
software system. The "pipeline" makes the disk abot to process commands while 
the computer is performing other jobs. This dramatically improves the overall 
throughput (input and output) of the sysleui. 

Diskettes tlrat yuu treate in this disk drive are read and write compatible 
with Commodore 404C and 203! disk drives. Therefore, diskettes can be used 
interchangeably on any of these systems. In addition, this drive can read 
programs created on the older Commodore 2040 drives. 

The 1541 disk drive contains a dual "serial bus" interface, This bus was 
specially created by Commodore. The signals of this bus resemble the parallel 
1EEE-48S interface used en Commodore PET computers, except that only one 
wire is used to communicate data instead of eight. The two ports at the rear of 
the drive allows more than one devi:e to share the serial bus at the same time. 
This is accomplished by "daisy -chaining" the devices togethsr.each plugged into 
the next. Up to five disk drives and one printer can share :he bus simultaneously. 



4 



Figure 1,1 Specifications VIC 1540/1541 Single Drive Floppy Disk 
STORAGE 



Total capacity 

Sequential 

Relative 

Directory entries 
Sectors per track 
Bytes per sector 
Tracks 
Blocks 



174848 bytes per disks Lis 

168656 bytes pet diskette 

167132 bytes pet diskette 

65535 records per file 

144 per diskette 

17 to 21 

256 

35 

683 (664 blocks free) 



IC*g; 



6502 

6522(2) 



microprocessor 
I/O. internal timers 



Buffer 
21 \c (4") 



2KRAM 



PHYSCIAL: 



Dimensions 
Height 
Width 
Depth 



97 mm 

:t)U mm 
3 "4 mm 



Electrical: 



Power requiiements 
Voltage 
Frequency 
Power 



100, 120, 220, or 240 V At 
50 or 60 Herts 
25 Watts 



MEDIA: 

Diskettes 



Standard mini 5V*\ single sided, 
single density 



2. UNPACKING AND CONNECTING 

Contents of Box 



Included with the 1541 disk drive unit, you should find a gray- 
power cable, black serial bus able, this manual, arid a demonstration diskette. 
The power rjable has a connection for the back of the disk drive on one end, and 
for a grounded (three-prong) electrical outlet on the other. The serial bus cable is 
exactly the same on both ends. It has a 6-pin DIN plug which attaches to the 
VIC 20, Commodore 64 or another disk drive. 



Please, 
section! 



don't hook up anything until you've completed the following 



.,. -,™ „ . _ sii"»ale drive 



i VIC1541 



- 



.1 



\ 



\ 



, DRIVE INDICATER (RED LED) 

~" I IfiHT: ACTIVF 
FLASH: ERROR 



POWER INDICATOR 



(GREEN LED) 

Fig 1 . Front Panel Li ght : powe n on 



Fig 2. Back Panel p ower swit ch 



SERIAL BUS 




= 



\r . 



AC INPUT 




FUSE/HOLDER. 



Connection of Cables 

Your first step is to ta'ie the power cable and insert it into the back of the 
disk arive (see Figure 2.2). If won't go in if you try to put in in upside down. 
Once it's in dre drive, plug the other end into the electrical outleL if the disk 
drive makes any sound at this tim*, please turn it off using the switch on the 
back! Don't plug any other cables into the disk drive if the power is on. 

Next, take the serial bus cable and attach it to either one of the serial bus 
sockets in the rear of the drive. Turn off the computer, and plLg (he other end 
of (he cable into the back of the compete;-. That's all there is tg itt 

If you :iave a printer, or any additional disk drive*, attach the cables into 
the second serial bus port (see figure 2.3). Fuj directions on using multiple drives 
at one time, read chapter 8. If you are a first-time ujei with more than one drive, 
start working with only one drive until you'te comfortable with the unit. 



Commodore 64 cr V1C2D 
"ersorral Cuviputer 



Single Drive 
Floppy Disk 




VIC (jraphic Primer 



Fg3. Floppy Disk Hookup 



Powering On 

When you have all the devices hocked together, it's time to start turning 
on the oower. It is important that you turn on the devices in the correct order. 
The computer should always be turned on last. As long as the contputer is the 
last one to be turned on, every thing will be OK. 

7 



First, make sure that you've removed all diskettes from the disk drives 
before powering on. 

After all the other devices have been turned on, only ther, is it safe to turn 
on the co:nput;r. Ail the Other devices will go through their starting sequences. 
The pointer's motor gues on, with .ht print head moving halfway across the line 
and back again. The 1 541 disk drive will have its red error light or., and then the 
green drive light will blink, while your TV screen forms the starting picture. 

Once all the lights have slopped flashing on the drive, it is safe to begin 
working with it. 



WRITE 

PROTECT 

NOTCH 



WHEN COVERED, DISKETTE 
CONTENTS CAN MOT BE 

ALTERED 




4 



33 
H 



O 

< 

m 



Fig.4. Position for Diskette Insertion 



Insertion of Diskette 

To open the door on the drive, simply press the door cstch hghtly, and the 
door will pop open. If there is a diskette ir the drive, it is ejected by a small 
spring, Take the diskette to be inserted, and place it in the drive face-up with the 
large opening going in first and the write-protect notch to the left (covered with 
tape in the demonstration disk) (see figure 2.4). 

Press it in gently, and when the diskette is in all the way, you will feel a 
click and the diskette will not spring out. Close the drive door by pulling 
downward until the latch clicks into place. Now you are ready to begin working 
with the diskette. 

Remember to always remove the diskette before the drive h turned off or 
on, Never remove the diskette when the green drive light is on! Da ID can be 
destroyed by the drive at this time! 

Using With a VIC 20 or Commodore 64 

The I 541 Disk Drive can work with either the VIC 20 or Commodore 64 



8 



computers. However, each computer has different requirements for speed of 
incoming data. Therefore, there is a software seitch for selecting which 
computer's speed to use, TKe drive starts out ready for a Commodore 64. To 
Mtefrcb to Vlf 20 speed, the following command must be sent after the drive is 

started (power-on or ihronrch software): 

OPEN 15,8, IS, "UI-": CLOSE 15 

To return the disk drive to Commodore 64 speed, use this command; 

OPEN 15,8,15, "UI+' : : CLOSE 1 5 

More about using this type of Command, is in chapter 4, with a detailed 
explanation of the U (user) commands in chapter 7. 

3. USING PROGRAMS 
LOADING PREPACKAGED PROGRAMS 

For those of you interested in using only prepackaged programs available 

on cartridges; cassette, or disk, here's all you have to do: 

Using your disk drive, carefully insert the preprogrammed disk so that the 
label on the disk is facing up and is closest to you. Look for a little notch on the 
disk (it might be covered with a little piece of tape). If you're inserting the disk 
properly, Tie notch will be on the left sice. Once the disk is inside, close the 
protective gate by pus hing in on th e ever. Now type LOAD "PROGRAM 
NAME", S and hit the ■HSllHltK'M key. The disk will make noise and your 
screen will say: 



SEARCHING FOR PROGRAM NAME 
LOADING 

READY 



When tire READY comes on and me ; >;is on, just type RUN, and your 
piepackajjed software is ready to use 

LOAD 

The BASIC commands used with programs on the disk drive are the same 
as the commands used on the Commodore DatassetteTM recorder. There are a 
few extra commands available tor use with disks, however. First of all, the 
progrsm name must be given with each command. On a Daiassette, you could 
omit the program name in order to just LOAD the fits program there. On disk, 
since there are many different programs that are equally accessible, the program 



name must be used to iel! the disk drive what to do. In addition, the disk drive's 
device number must be specifier! If no devire number is listed, the computer 
assumes the program is on tape, 

FORMAT FOR THE LOAD COMMAND: 
LOAD nameS , device* , command* 

The prsgrairi name is a siring, that is, either a name in quotes or the 
contents of a given string variable. Some valid names are; "HELLO", 
"PROGRAM #1 ". AS, NAMES. 

The device* is preset on the circuit board lo be #8. If yoi, have more than 
one drive, sec chapter 8 on how to change the device number. This book assumes 
that you're using ccvitc number 6 Tor the disk drive. 

Tiie uuTn:iand# is optional, If not given, tn /.etu, the piugiam is LOADeJ 
normally, that is, beginning at the sun of your available memory for BASIC 
programs. If the number is 1, the program will be LOADed at exactly the same 
memory locations from which it came. In the case pt computers with different 
memory configurations, like VIC's with 5K, 8K, or more memory, the start of 
BASIC memory is in different places. The command* permits BASIC 
programs to LOAD normally, Command* I is used mainly for machine 
language, character sets, and other memory dependent functions. 

EXAMPLES 

LOAD "TEST", 8 

LOAD "Program #1", 8 



LOAD AS, J *K: 
LOAD"MachLang", 8, 1 




NOTK: You can use variables to represent device numbers, commands, anc 
strings, as long as you've previously definsd them in you* program. 



Directory of Diskette 

Your DatasBette^M tape deck is a sequential device, It can only read from 
the beginning of the tape to the end, without skipping around the tape and 
■tvitbout the capability of going backward or recording over old data. 

Yrjut disk drive is a random access device. The read/write head of the disk 
can go to any spot tin the disk and access a single block of data which holds up 
to "25b by tesot information. There are a total of 683 blocks on a single diskette. 

.Fortunately, you don't redly have to worry about individual blocks of 
data. There is a program in the disk drive called the Disk Operating System, or 
the DOS. ThJS program keeps track of the blocks for you. It orgamzes them into 
a Block Availability Map, or BAM, and a directory. 

10 



The Block Availability Map is simply a checklist of all 683 blocks on the 
disk. It is stored in the middle of the diskette, halfway between the center hub 
and the outer rim. Every lints a piogram is SAVEd or a data file is CLOSEd, the 
BAM is updated m.h the list of blocks used up. 

The directory is a list of all programs and other files stored on the disk. It 
is physically located right next to the BAM. There are 144 entries available it: 
the directoty, consisting of information like file name and type, a list of blocks 
used, and the starting block. The directory is automatical^ updated every time £ 
program is SAVEd or a file is OPENed for writing. Beware: the BAM isn't 
updated until the file is CLOSEd, evsn though the directory changes right away. 
If a Tile isn't CLOSEd properly , all data in that file will probably be lost. 

Tlii" directory can he LOADed into your memory just like a BASIC 
program. Place the diskette in the drive, and type the following command: 

LOAD "S'\ 8 

The computer responds with: 



SEARCHING FOR S 

FOUNDS 

LOADING 



Now the directory is in your computer's memory. Type LIST, and you'll 
see the directory displayed on (he screen. To print the dtieetory on your prin'.er, 
type the following command line (in this example your printer is plugged in as 
device* 4): 

OPEN 4, 8, 4: CMD 4: LIST 



NOTE: When using CMD, the Tile must he closed using the command 
PRINT* 4: CLOSE 4. See the VIC 1 525/ 151 5 printer manual for detailed 
explanation. 



To read the djrestory without LOADing it into your memory, see the 
section later in this chapter on the DOS Support Program. In addition, to 
examine the directory from inside a BASIC program, sse the section in chapter 5 
that deals with the GET# statement. 

Pattern Matching and Wild Cards 

When using the tape deck, you can LOAD any program starting with 
esjtain letters just by leaving off any following letters. Thus, the command 

11 



LOAD "T" will find the f;ra program on the tape beginning with the letter T. 
Anc LOAD "HELLO" will find the first nrogram beginning with the letters 
HELLO, like "HELLO THfcRh." 

When using the disk, this option is called pattern matching, and there is a 
special character in the file name used :o designate this. The asterisk (*) 
character following any program name tells the drive you want to find any 
program starting with that name. 



FORMAT FOR PATTERN MATCHING 



LOAD narneS + "*", 8 




In udier words, if you wan I to LOAD the firsi program on lire disk 
starting with the letter T. use the command LOAD "T + ", 8. 

it only the "* :s used for the name, the last program accessed on the disk 
is the one LOADed. if no program has yet been LOADed, the first one listed in 
the directory is the one used. 

Vou are probably familiar with the concept of wild cards in poker where 
one CErd can replace any other card needed. On your 1541, the Question mark 
(?) can be used as a wild card on the disk. The program nam; on the disk is 
compared to the name in the I OAD command, but any characters where there is 
a question mark in the name aren't checked 

For instance, when the command LOAD "T7NT", $ is given : programs 
thai match include TINT, TENT, etc 

When LOADing the directory of the disk, pattern matching and wild cords 
can be used to check Tor a list of specific programs. If you gave the command 
LOAD "£0:TEST", only the program TEST would appea; in die Uiiectory (if 
present on the disk). The command LOAD "50:t*" would giveycu a directory 
of all programs beginning with the letter T. And LOAD "S0:T?5T" ivould give 
you all the programs with 4-letter names having the first letter ot 1 and the third 
and fourth letters ST. LOAD "S0:T?ST*" would give names nf any length with 
the correct first, third, and fourth letters, 

SAVE 

To SAVE a program to the diskette, all that is needed is to add the device 
number after the program name. Jus-, like the SAVE command for the tape 
deck, the device number can be followed by a command number, to prevent the 
automatic re-location on LOADing (see the section on the LOAD command, 
above), 

FORMAT FOR THE SAVE COMMAND: 

SAVE namel, device*, command* 

12 



See the LOAD command images & | for an explanation of die 
para meters device* and commands. 

When yuu tell the disk drive to SAVE a program, the DOS must take 
several steps. First, it looks at the directory tc see if a program with that name 
already exists. Next it checks to see that there is a directory entry available for 
the name. Then it checks the BAM to see if thsre ate enough blocks in which to 
stole the program. If every thing is OK up to this point, the program is stored. If 
not. the error light will flash, 

SAVE and Replace 

If a program already exists on the disk, i: is often necessary to make a 
change and re-SAVE it onto the disk. In this case, it would be inconvenient to 
have to erase (he old version of the program and then SAVE it. 

If the firsi characters of the program name arc thc"fi" ;ign followed by a 
and a eolon {: ). the DOS knows to replace any old ptogram that has that name 
wirh the program that is to* in the computer's memory. The drive checks the 
circa ory tu find the old progran, then it marks that entry as deleted, and it 
next creates a new erifiy with llic same name. Finally, the piogiam is sluied 
normally . 
FORMAT FOR SAVE WITH REPLACE: 

SAVE "—0:" + larneS, device*, command* 

f-or example, if a file was called TEST, the 5AVE and replace command 
would be SAVE"(«U: 1 EST .8. 

The reason for the 0: is to keep compatibility with other Commodore d:sk 
drive units which have mere than one drive built in. In ihat case, the number 

or 1 is used to specify which drive is being used. 

VERIFY 

The VERIFY command works to cheek the program currently in memory 
against the program on disk Yoti must include a device* with ihe VERIFY 
command. The computei does a byte-by-byte comparison o~ the program, 
including line links— which may be different for different memory configura- 
tions. For instance, if a program was SAVEd to disk from a 5K VIC 20, and 
rc-LOADcd on an 8K machine, it wouldn't VERIFY properly because the links 
point to different memory locations. 

FORMAT FOR VERIFY COMMAND: 

VERIFY nameS. device* 



13 



DOS Support Program 

On your demonstration disk, there may he a program railed D05 
SUPPORT. This program, also called a wedge, allrw? yon to use many disk 
commands more easily (different wedges are. ussd for the VIC 20 and the 
Cnmmcidorp 64) .list LOAD the program and RUN it. It automatically sets 
itself up and erases :tselfwrieri it's finished You'll have a few hundred less bytes 
to work with when th:s program is running, but youll also have a handy way to 
send ths disk commands. 

As a lesull of the DOS Support, ihe "/" se/ now takes the place of the 
LOAD command. Just Ml the slush followed by the program name, and the 
program is LOADed, When you use this method, yen. don't need tc use the 
LOAD command or the c anuria S. 

The"**"' and ">" keys are used to send commands to the disk drive. If you 
type ( fl S (or >S). the directory pf the cisk is displayed on the screen, without 
LO ADing into your memory! These keys also take the place af the PRINT* ("see 
chapter 4) to send commands listed in the next chapter. 

To read the error channel of the disk (when the red error light is blinking), 
just hit ekher the (" or the > and hit RETURN. The complete error message is 
displayed to you: message number, text, and track and block numbers 



4- DISK COMMANDS 

OPEN and PRINT* 

Up 'til now, you hive explored the simple ways of dealing with the disk 
drive, In order to eorirr.unicate with the disk drive more fully, you have to 
touch on the OPEN and PStlNT* statements in BASIC (more details uf Ihese 
eornmands are available in your VIC 20 or Commodore 64 User's Guide or 
Programme's Reference Guide). You niiy be familiar with [heir use with data 
files on cassette tape, where the OPEN statement creates tie file and the 
PR1NT# statement fills the file with data. They an be used the same way with 
the disk, as you will see in the next chapter. But they can also be used to set up 
a command channel. The command channel lets you exchange information 
between, the computer and the disk drive. 

FORMAT KORT'HbOftN STATEMENT: 

OPEN file#, device*, (com in and) channel*, texr $ 

The file* can be any number f.om 1 to 255 This number is used 

throughout rite program to identify which file is being accessed. But numbers 
greater than 127 should be avoided, because tliey cause the PRINT* statement 
to generate a linefeed after the return character. These numbers are really meant 
Id be used wilh non-standard printers. 

14 



The device* of the disk is usually ft. 

The channel* can be any number Iron) 7 to 15. These refer to a channel 
used to communicate with the disk, and channels numbered and 1 are reserved 
for the operating system to use for LOADing and SAVEing. Channels 2 through 
14 can be used for data to files, anc 1 5 is the command channel. 

The texts Is i suing thai Is PRlNTed to the Tile, as if with a PRINT* 
statement. This is h andy for sending a single command to the channel. 

EXAMPLES OF OPEN STATEMENTS 

OPEN IS, 8. 15 




DPEW2.8.2 
OPEN A. B, C,Z$ 



The PRINT* command works exactly like a PRINT statement, except 
that Hie data goes to a device ;Mher than the screen, in this ease to the disk drive. 
When used with a cata channel, the PRINT* sends information into a buffer in 
the disk drive, which LOADs it onto the diskette. When PRINT* is used with 
the command channel, it sends cotrmands :o the d;sk diive, 

FORMAT FOR SENDING DISK COMMANDS: 



or 



OPEN 15,8, 15. commands 



PRINT* 15, commands 



NEW 

Tins command is necessary when using a diskette for the first time. The 
NEW command erases the entire diskette, it puts timing and hloek markers on 
the diskette and creates the directory and BAM. The NEW command can also be 
used to clear out the directory of an already -format ted diskette This is faster 
than re-formatting the whole cisk. 

FORMAT FOR THE NEW COMMAND TO FORMAT DISK: 

PRINT #15, "NEW^t^eld 7 
or abbreviated as 

PR1NT#15, "N0:name.id" 

FORMAT FOR THE NEW COMMAND TO CLEAR DIRECTORY: 

PRINT* 1 5, "Nf name" 

The name goes in ihe directory as the name of the entire disk. This only 
appears when the directory is listed. The ID ;ode is any 2 characters, and they 
arc placed not only on the directory but on every block throughout the diskette. 

15 



That way, if you carelessly replace diskettes while writing data, the drive will 
know by checking the ID that something is wrong 

COPY 

This command allows you to maka a copy of any program or file on the 
disk drive, 11 won't copy from one drive to a different one {except in the case of 
dual drives like the 4040), but it can duplicate a program under another name on 
the diive. 

FORMAT FOR THE COPY COMMAND; 

PRINT* I 5, ''COFY^:newtile=^^idfih? 
or abbreviated as 

PRINT* 1 5, "cP:new:"ile=0:oldfile" 

The COPV command can also be used to combine two through four Tiles 
on the disk. 

FORMAT FOR COPY TO COMBINE FILES: 

PRlNT#IS,"CO:newfde=0:o!dfdel,0:oldfile2,0:oldrile3,0:oldfile4" 

EXAMPLES OF COPY COMMAND: 

PRINT# 15, "CC:BACKUP=C:ORIGINAL" 

PRINT*! 5, "CO:MASTERFILE=0:NAME,0:ADDRESS,0:PIIONES" 

RENAME 

This eorr.mand allows you to change the name of a file once it is in the 
disk directory. This Is a fast operation, since only the name in the directory must 
he changed. 

FORMAL FOR RENAME COMMAND: 

PRINT* IS, "RENAME0: newtiam3=oldname" ^^^DRIVeT) 

or abbreviated as ' — ■***-" 

PRINT* 1 5, "R0:n2wname=cldiiame" 

EXAMPLE OF RENAME COMMAND: 

PRfNT#1 S, "R0:MYRA=MYRON" 

The RENAME command will not work on any tiles that are currently 
OPEN. 



16 



SCR\TCH 

This command allows you to erase unwanted files and programs from the 
disk, which .hen makes the blocks available for new information. You can erase 
programs one at a time or in groups by using pattern matching and/or wild cards, 

FORMAT FOR SCRATCH COMMAND 

PRINT* 1 5, "SCRATCH^ name" 
or abbreviated as 

PRINT* 15. "S0:nam?" 

If you check the error channel alter a scratch operation (see below), the 
number usually reserved lor the track number now tells you how many files 
were scratched. For example, if your directory contains the programs KNOW 
and GNAW, and you use the command PRINT* 15, '-S0:?N?W", you will 
scratch both programs. If the directory contains TEST, TRAIN, TRUCK, and 
TAIL and you command the disk to PRINT* 15, "SC:T*", you will erase all 
four of these programs, 

INITIALIZE 

At times, an error cor.dition on the disk will prevent you from performing 
some oneratior. you want to do. The INITIALIZE :ommand relurrrs the disk 
drive to the same slate as when powered up. You must be careful to re-match 
the drive to the comouier (see chapter 2) 
FORV1AT FOR INITIALIZE COMMAND: 

PRINT* IS, "INITIALIZE'" 
or abbreviated as 

PRINT* IS, "I" 

VALIDATE 

After a diskette has beeji in Lse for some time, the directory can become 
disorganized. When piogiarns have been repeatedly SAVEd and SCRATCHed, 
they may leave numerous small gaps on the disk, a block here and a few blocks 
there. These blocks never get used because they ars too small to be useful. The 
VALIDATE command will go in and re-organi?.e your diskette so that ycu can 
gel the most from the available space. 

Also, there may be data files that were OPENed but never properly 
CLOSEd. This command will collect all biocks taken by such files and make 
them available to :he drive, since the files are unusable at that point. 

There is a danger j n using this command When using random files (see 
chapter 6), blocks allocated will be de-allocated by this command. Therefore, 
this command should never be used with a disket-e -.hst use; random file; 



17 




FORMAT FOR VALIDATE COMMAND: 

PRINT* 1 5, "VALIDATE" 

or abbreviated as 

PRINT* 1 5, "V" 

DUPLICATE 

Ihis command is a handover from the operating systems that were 
contained on trie dual drives iike the 4040. It was used to copy entire diskettes 
from one drive to another, but has no function on a single disk drive 

Reading the Error Channel 

Without the DOS Support Program, there is no way to read the disk error 

channel without a program, since you need to cse the INPUT* command which 

won't work outside a program. Here is a simple BASiC routine to read the error 

channel: 

ERROR* 



10 OPEN 13,8, 15^ 

25 INPUT* 15, AS, BS,CS,DS 

JO PRINT AS,BS,C5,DS 

Whenever you perforin an INPL'T* operation from the command channel, 
you read up to 4 variables that describe the error condition. The first, third, and 
fourth variables come in as numbers, and can be INPUT into numeric variables if 
you like. The first variable describes the error #, where is no error. The second 
variable is the error description. Tf.e third variable is the track number on which 
the error occurred, and the fourth and final is the block number inside that 
track, (A hlock is also known as a sector) 

Errors on track IS have to do with the BAM and directory. For example, a 
READ ERROR on track 18 block may indicate that the disk was r.ever 
formatted. 

CLOSE 

It is extremely Important that you properly CLOSE files once you are 
finished using them Closing the file causes the DOS tc properly allocate blocks 
in the KAMand to finish the entry in the directory, If you don't CLOSE the file, 
all your data will be lost! 

FORMAT FOR CLOSE STATEMENT: 
CLOSE file* 

You should also bo careful not to CLOSE the error channel (channel* 15) 
18 



before CLOSEing your data channels. The error channel should be OPENed first 
and CLOSEd last of all your files! Dial w 11 iteep your programs oul o" trouble. 

If vou close the error channel wHle o;her files are OPEN, the disk drive 
will CLOSE ihera for you. but BASIC will slill think, they are open (unless you 
CLOSE then properly), and let you to try ;o write to them. 

NOTE: If your BASIC program le ids you into an error condition, all files 
are CLOSEd in BASIC, without CLOSEing them on your disk drive! This 
is a very dangerous condition. You should immediately type the Statement 
CLOSE IS: OPEN IS, 8, IS: CLOSE IS, This will rc-initializc your drive 

and make all your files safe. 



5. SEQUENTIAL FILES 

OPEN 

Sequential files on the disk drive wors exacty like :hey do on cassette 
tape, only much faster. They are limited by their sequer.ttfiJ nature, which means 
they must be read from beginning :o end. Data is transferred byte by byte, 
through e buffer, onto the magnetic media. To the disk drive all files are created 
equal. That is. sequential file;, program files, and user files all work the same on 
the disk. Only program files can be LOADed, but that's really the only 
difference. Even the directory works like this, except that it is read-only. The 
only difference is with relative files. 

FORMAT FOR OPENING A SEQUENTIAL FILE: 

OPEN file*, de vice #, channel*. "Oiname.type.direction" 

The file number is the same as in all your other applications of the OPEN 
statement, snd it is used througriOJt the program to refer to this particular file. 
The device# is usually 8. The char.nel# isa data channel, number 2 through 1-1. 
It is convcr.icnt to use the same number for both the channels and filc#, to 
keep thern straight, The name is the file name {no wild cards or pattern matching 
if you're creating a write file). Ttw type can be any of tine ones from the chart 
below, al least the first letter of uaeh type. The direction musl be READ or 
WR1TF.. or a: leasr [tie first lerier of cacti. 

FILE TYPE MEANING 

PRG Program 

SEQ Sequential 

USR User 

REL Relative (not implemented in BASIC 2.0) 



19 



EXAMPLES OF OPENING SEQUENTIAL FILES: 

OPEN2.8, 2jf'0DATA,S,W" ^"~V~FILE NAME 

OPEN 8, 8, 8 r «Progtarn, P, R';T~" ~~~^~CZ^E- 

OPEN A, B, C, "D: " + AS 4 "U, W" "^READ/WRITE 

If tie file aheady exists, you can use the replace upLiun in the OPEN 
statement, similar to the SAVE-and-replace described in chapter 3. Simply add 
the (">0: before the file's name in the UFtN statement. 

EXAMPLE OF SEQUENTIAL FILE WITH REPLACE OPTION: 

OPEN 2, 8, 2, "C*-0:DATA,S,W" 

PRINT* and INPUT* 

The PRINT* command works exactly like the PRINT statement, except 
that output is re-diree'ed to the disk drive. The reason for the special emphasis 
on the word exactly is that all the formatting capabilities of the PRINT 
statement, as applies to punctuation and data types, applies here too. It just 
means that you have to ba careful when putting data into your files, 

FORMAT FOR WRITING TO FILE WITH PRINT* 

PRINT* file* data list 

The file* is the one from the OPEN statement when the File was created. 

The data list is the same as the regular PRINT statement-a list of variables 
and/or text inside quote mirks. However, you must be especially careful when 
writing data that it is as easy as passible to read back sgain [atsr. 

When using the PRINT* statement, if you use commas (,) to separate 
items on the line, the items will be separated by some blank spaces, as if it were 
being formated for the screen. Semicolons (;) don't result in any extra spaces. 

In order to mare fully understand what's happening, here is a diagram of a 
sequential file created by the s:atement OPEN 5, 8, 5, "0:TEST5,W": 

tot 



cHet .1 



10 II 12 13 1+ 15 



The eof stands for the end-of-file marker. String data entering the file goes 
in byte by byte, including spaces 

For instance, let's set up some variables with the statement AS= 
"HELLO"; BJ= "ALL": C£= "BYE". Here is a picture of a file after the 

20 



statement PRINT* 5 ; AS; B5; CS: 



|h 


F 


1 


i | n 


A 




ft 


Y 


E 1 fR 


BCf 


Lha; J 1 


2 


3 


4 \ 5 


6 


t 1 a 


9 


10 


II | 12 


1.! 



CR siands tor the CHRS code of 13, the carriage return, which is PRINTcd 
at the end of every PRIM or PRINT* statement unless there is a comma or 
semicolon at the end of the line, 

NOTE: Do not leave a space between PRINT and *. and do not try to 
nbhreviate the command as ?# See the appendixes in the user manual for 
the correct abbreviation. 

FORMAT FOR INPUT* STATEMENT: 

INPUT* file*, variable lis: 

When using the !NPUT# to read this data in, there is no way to tell that 
iL's not supposed to be one long stiing. You need something in the file to act as a 
separator. Characters to use: as separators induce ths CR, a comma or a 
semicolon. The CR can be added easily by just using one variable per line on the 
PRINT* statement, and the system puts one there automatically. The statement 
PRINT* 5. AS: PRINT# 5. BS: PRINT* 5, CS puts a CR after every variable 
being written, providing the proper separation for a statement like INPUT*5, 
AS, BS, CS. Or else a line like ZS= ",": PRINT* 5, AS ZS BS ZS US will do the 
job as well, and in !ess space. The file after that line looks like this; 





H 


F 


t 


1. 







A 


r. 


I, 


I R 


Y 


t. 


CR 


eoF 


char 


1 


2 


1 


4 


1 


6 


7 


8 


□ 


10 11 


12 


13 


14 


15 



Putting Commas between variables results in lots of extra spate on the disk 
being used. A statement like PRINT* 5, AS, BS makes a file that looks like: 





11 


D 


t. 


L 















A 


L 


L 




CR tof 


char 


' 


: 


.3 


4 


5 





7 


8 9 


10 


11 


.2 


13 


14 


... 


13 24 



You can s;e that much of the space hi the f.le is wasted. 

The moral of all this is: take cire when using PRINT* so your data will be 
m order for reading back: in. 

Numeric data written in the file takes the form of a string, as if the STRS 
function had been performed on it before writing it out. The first character will 
be a blank space if the number is positive, and a minus sign (-) if the number is 
negative. Then comes the number.and the last character is the cursor right 
character. This fotmat provides enough information for the INPUT* statement 
to read them in as separate numbers if several are written with no other special 
separators. It is somewhat wasteful of ipsce, since there can be two unused 

21 



characters if the numbers are positive. 



Here is a picture of the file after the statement PRINT* 5, 1; 3; 5; 7 is 
performed: 



cliar I 2 3 4 5 6 7 « 9 10 11 12 13 14 15 

Appendix B contains a program demonstrating the use of £ sequential disk 
file, 

GET# 

The GET* retrieves da:a from the disk, one character at a time. 

FORMAT FOR THE GET* STATEMENT; 

GET* file*^ variable list 

Data comes, in byte by byte, including the CR, comma, and other 
separating characters. It is much safer to use string variables when using r Jie 
GET* statement. You will get a BASIC srror message if string data is received 
where a number was requested, but not vice-veisa, 

EXAMPLES OF GET* STATEMENT: 

GET* 5, AS 

GET* A, B$, C$, DS \ You can get more than 1 character at a time 

GETS 5, A 

The GET* statement is extremely useful when examining files with 
unknown contents, like a file that may have been damaged by an experimental 
program. It is safer than INPUT* because there is a limit to the number of 
characters allowed between separators of INPUT variables. With GET* ^ou 
receive every character, and you can examine separators as well as other data. 



disk: 



Here is a sample program that will allow you to examine ar.y file on the 



I U INPUT "FILE NAME"; FS 

20 INPUT "FILE TYPE";TS 

30T5=LEFTS(TSJ) 

40 IF T$ <> "S" THEN IF TS <> "P" THEN IF T$ <> "U" THEN 20 

45 OPEN 1 5, 8, 15 

50 OPEN 5, 8, 5, "0:" + F$+ ","-t TE+ ",R" 

60 GOSUB 200 



22 



70GET+5, A$ 

80 IF ST <>0 THEN PRINT ST: STOP 

90 PRINT ASC(AS+CHRS(0) ); 

1 00 GOTO 7 *>^ 

20O INPUT* 15, AS, B$ CI, D$ 

210 IF VAL(AS) >0 THEN PRINT A$,BS,CS;D$:STOP 

220 RETURN 




Reading the Directory 

The directory or the diskette may be readjust like a sequential file. Just 
use S for tie file name, and OPEN 5, 8, 5, "$". Nov/ the GET# statement works 
to examine the cirectury ■ The format here is identical to the format of a 
program file: the file sizes are the line numbers, and names are stored as 

characters within quote marks. 

Here's a program that lets you read the directory of the diskette: 



10OPRN1 8,7, "S 
20GET#I.AS,A$,AS,AS 
30T$(0i="Der':T$(l) = 
-101=17 GOSUBS 00 
50NS=BS 

601-2 < -i l ^J 

70 GOSUB500 — ' 

80 l$=BS 

90J-2 *- 



"SEQ":TS(2) ■ "PRG":T$(3) = "USR":TS(4) = "REL" 




100 GOSUB500 
I10 0$=B$ 

120FOR01TO 

13UGET#1,A$,A$,AS 

140 NEXT 

ISO GET#I,AI,AS,A5.A$,AS 

1 60 PRINTCHRS( 147) "Disk name: "NS,"ID: "JS/'OS: "0$ 

161 PRINT"UnEth","Tvp«","Name" 
165F0RP=lTO6 
170GET#1,TS,A$,A5 
175IF5TTHENCL0SE1:END 

1 SO I FT$=""THENTS=CHRS[ 1 2S) 




190 J=15 ^ 

200GOSUBS0O 

2^(1 M=R$ 

220 CET#l.AJ,Al.AS,AS,AS,AS,AS.AS J ASAiLS,HS ' 

225L=ASCl'LS+CHRS(O))4256*ASC(HJ+CHRS(0)rlFL=0THF.N250 

230 PRINTL,TS(ASC<TS)-128),NS 

250 IFP < STHENGET#l ,A$,AE 

260NEXTP:GOTO16S 



23 



500 B$="" 

510FORL=OTOJ 

520GET#1,AS 

530 IFA$ < > CHRJ(96)THENIFA$ 

540 NEXT 

550 RETURN 



: > CHRS(ieO)THENBS=B$+A$ 



, BUILD A 

■ STRING 

; SUBROUTINE ' 



Table 5.1: 1540/1541 BAM FORMAT 



Track 18, Sector 0. 


BYTE 


CONTENTS 


DEFINITION 


0,1 


lfi,0l 


Track and sector of first directory block 


2 


65 


ASCII character A indicating 4040 format, 


3 





Null flag for future DOS use. 


4-143 




Bit map af avail able blocks for trac a 1—35. 


*I ■ available block 
= block not available 

(eacti tit represents one block) 



Table 5.2: 1540/1541 DIRECTORY HEADER 



Track 18, Sector 0. 


BYTE 


CONTENTS 


DEFINITION 


144-161 




Disk, nanie raided with shifted spaces. 


162-163 




Disk ID. 


164 


160 


Shifted space. 


165,166 


50,65 


ASCII representation for 2A which is DOS version 
and format type, 


166-167 


160 


Shifter! spaces. 


171-255 





Nulls, not i.sed. 


Note: ASCII characters nay appear in locations 180 thru 191 on some diskettes. 



2^ 



Table 5.3: DIRECTORY FORMAT 



Track IS, Sector 1 for 4040 
Track 39, Sector 1 for 8050 


BYTE 


DEFINITION 


0,1 


Track and sector of next directory block. 


2 n 


*File entry 1 


J4-63 


*r-il2 entry 2 


66-9 5 


*Fjle entry J 


98-127 


*Fils entry 4 


130-159 


*Fils entry 5 


162-191 


"File entry 6 


19^—223 


*File entry 7 


226-255 


*File entry 8 



♦STRUCTURE OF SINGLE DIRECTORY ENTRY 



BYTE 


CONTENTS 


DEFINITION 





128+type 


File type OR'ed wilh $80 to indicate properly dosed 

file. 

TYPES: 0=DELeted 

1 = SEQential 

2 = PROGram 
3= USER 

4 = RELative 


1.2 




Track and sector of 1st data block. 


3-; 8 




Filename padded with shifted spaces. 


19,20 




Relative file only: track and sector for first side settui 
block. 


21 




Relative file only; Record size. 


22—25 




Unused. 


26,27 




Track and sector of replacement file when UFEN^'isin 
effect. 


28.29 




Number of block* in file: low byte, high byte. 



25 



Tsble 5.4: SEQUENTIAL FORMAT 



BYTE 


DEFINITION 


0,1 


T'ack and sectnr of next sequential rtata block 


2-256 


254 bytes of data with carriage returns as record terminators, 



Table 5.5: PROGRAM FILE FORMAT 



BYTE 


DEFINITION 


0.1 


Track and lector of next block in program file. 


2-256 


254 bytes of program info stored in CRM memrry forma? (with 
key words tokenized). End of file is marked by three zero bytes. 



6. RANDOM FILES 

Sequential files are fine when you're just working with a continuous 
stream of data, but some jobs require mere than that. For example, with a large 
nailing list, you would not want to have to scan through the entire list to find a 
person's record. Far this you need some kind of random access method, some 
way to get to any record inside a Tile without having to read through the entire 
file first, 

There are actually two different types of random access files on the 
Commodore disk drive The relative files discussed in the next chapter are more 
convenient for data handling operations, although the random tT.es in this 
chapter have uses of their own, especially when working with machine language. 

Random files on the Commodore disk drive reach the individual 256-byte 
blocks of data stored on the disk As was mentioned in the first chapter, thsre 
aie a total of 683 block: on the diskette, of which 664 are free on a blank 
diskette. Each block of dhtv. mally means 1 Track and sector of the same name. 

The diskette is divided into tracks, which are iaid out as concentric circles 
on the surface of the diskette. There are 35 different tracks, starting with, track 1 
at the outside of the diskette to track 35 at the center. Track IS is used for the 
directory, and the DOS fills up .he diskette from lite center outward. 

Each track is subdivided into sectors. Because there is more room on the 
outer tracks, there are more sectors there The outer tracks contain 21 sectors 
each, while the inner ones only have 17 blocks each. The table below shows the 
number of sectors per traci. 



26 



TRACK NUMBER 


SECTOR RANGE 


lOTALSfcCTOKS 


1 to 1 7 
IS to 24 
25 to 30 
31 to 35 


to 70 
:o 18 
0lol7 

Oto 16 


21 
19 
18 

17 



Th: DOS contains commands for reading and writing directly to any uack 
and sector on the diskette. There are also commands f°i checking to see which 
blotki(tiai;k!.(SL sec tors) are available, and for marking off used blocks. 

These commands are transmitted through th-3 command channel 
(channel* 15), and tell the disk what to do with the data. The data must be read 
Ister through one of the open data enamels. 

Opening a Data Channel for Random Access 

When working with random access files, yon need to have 2 channels open 
to the disk: one for the commands, and the other for the data, The command 
channel is OPENed to channel 15. ust like other disk commands you've 
encountered so far. The data channel For random access files is OPENed by 
selecting the pound sign (#) as trie file name. 

FORMAT FOR OPEN STATEMENT FOR RANDOM ACCESS DATA: 

OPEN file* device*, channel* "#" 
Or optionally 

OPEN file #. device*, channel* "# suffer*" 

EXAMPLES OF OPENING RANDOM ACCESS DATA CHANNEL: 

OPEN 5. 8. 5. "#" 

OPEK A, b. C, "#. 

BLOCK-READ 

FORMAT FOR BLOCK-READ COMMAND: 

PRINT* fix*. "BLOCK-READ:" channel, drive, track, block 
or abbreviated as 

PRINT* file*. "B-R:" channel. <lrtVS, track, block 

This command wlI move one block of data from the diskette into the 
selected channel. Once this operation has been performer:, the INPUT* and 
GET#statement5 can read the information. 




27 



SAMPLE PROGRAM TO READ BLOCK 2 FROM TRACK IS: (stores con tants 
inDS) 



JO OPEN 15,8, 15 

20 OPEN 5, 8, 5,"*" 

30PRINT# )5."B-R:" 5, ( 

40 BS=" ,T 

50 FOR L=0 TO 255 

60 GET* 5. AS 

70 IF ST=0THFN B£= RS+ AS: NHXT L 

80 PKJNT "FINISHED" 

90 CI OSF S: CLOSE 15 




= BLOCK. 



COLLECT ENTIRE BLOCK. 
BYTE BY BYTE 



BLOCKWRITE 

The BLOCK-WRITE command is the Hid opposite of the BLOCK-READ 
command. First you must fill up a data buffer with your in forma '.ion, then you 
write that buffer to ihe correct location on the disk. 

FORMAT FOR BLOCK-WRITE COMMAND: 

PRINT#file#. "BLOCK-WRITE:" drive, channel, track, block 
or abbreviated as 

PRINT* file, "B-W:" drive : channel, track, block 

When the data is being put into the buffer, a pointer in the DOS keeps 
track of how mar.y characters there are. When you perform the BLOCK-WRITE 
operation, that pointer is recorded on the disk. That is the reason fcr the ST 
check in line 70 of the program above: the ST wi'I become non-zero when you 
try to read past the end-of-file marker within the record, 

SAMPLE PROGRAM TO WRITE DATA ON TRACK 1 , SECTOR 1 : 

10 OPEN IS, S, 15 

20 OPEN 5,8,5,"*" 

3QFORL=I 10 50 

40 PRiNT#5, "TEST" 

50 NEXT 

60 PRINT* IS, "B-W:" 5, 0, 1, 1 

70 CLOSE 5: CLOSE 15 



28 



BLOLK-ALLOCATE 

In order to safely use random files along with regular tiles, your programs 
must check the &AM to find available blocks, and change the BAM to reflect 
that you've used them. Once you usdate the BAM, your random files will be 
safe-at leasi unless you perform the VALIDATE command (see chapter 3). 

FORMAT FOR THE BLOCK-ALLOCATE COMMAND 

PRINT* file*, "BLOCK-ALLOCATE:'" drive, track, block 

How do you know which blocks arc available to use? If" you try a block 
that isn't available, the DOS will set the error message to number 65, NO 
BLOCK, and set die track and block numbers to the next available track and 
block number. Therefore, any time you attempt to write a blo:k to the disk, 
you must first try to allocate that block. If that block isn't available, read the 
next block available fram the srror channel and then allocate that block. 

EXAMPLE OF PROCEDURE TO ALLOCATE BLOCK: 

10 OPEN 15,8. IS 

20 OPEN 5, 8. S, "# 

30 PRINT* 5, "DATA 1 " 

40T-LS-1 /f 

5OPR[NT#]5,"B-A:"0,T,S 

60INPUT#15. A, B$, C,D 

70 IF A=65 TH£NT=C: S=D: GOTO 50 

80 PRINT* 15, "B-W:" 5, 0, T. S 

BLOCK-FREE 

The BLOCK-FREE command is the opposite of BLOCK-ALLOCATE, in 
that it frees a block thai you don't want to use anymore for use by the system. 
It is vaguely similai to the SCRATCH command for files, since it doesn't really 
erase any data from the disk— just frees the eritry , in this case just in the HAM. 

FORMAT FOR BLOCK-FRFE COMMAND- 

PRINT* fiie#, "BLOCK-FREE:" drive, track, block 
oi abbreviated as 

PRINT* file*, "B-F:" drive, track, block 

Using Random Files 

The enly prnblem with what ygu'vs learned about random files so far is 

29 




that you have no way of keeping Lack of which blo:ks on the disk you used. 
After all, you can't tell one used block on the BAM trorr, another. You can't teL" 
whether it contains your random fiie, just part of a program, or even sequential 
or relative files. 

To keep track, the most common method is to build up a sequential file to 
e;o with each random file. Use this file to keep just a list of record, track, and 
block locations. This means that there are 3 channel; open to the disk for each 
random file: one for the command channel, one for the random data, and the 
other for the sequential data. This also means that there are 2 buffers that you're 
filling up at the same time! 

SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS BLOCKS WITH 
SEQUENTIAL FILE: 

10 OPEN 15,8, 15 

20 OPEN 5, 8, 5, "# 

30 OPEN 4, 8, 4, "<£0:K.EYS,S,W" 

40 AS= "Record Contents #" 

50FORR=1 TO 10 

70FKlNT'#5 f AS'V'R 

90T=1: S=l 

100 PRINT* l5,"B-A-"0, T, S 
110 INPUT* 15, A, BS.C.D 
120 If- A=65 THEN T=C: S=D: liOTO 100 
130 PRINT* 15,"B.W:" 5, 0, T, S 
140 PRINT* 4, T","S 
1 50 NEXT R 
160 CLOSE 4: CLOSE 5: CLOSE IS 

SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS WITH 
SEQUENTIAL FILE: 

I0OPEN 15,8, 15 

20 OPEN 5, 8, 5,"#" 

30 OPEN 4, S, 4, "KEYS,S,R" 

40FORR=1 TO 10 

50 INPUT* 4, T,S 

60PRJNT* 1 5, "B-R:" 5, 0, T, S 



30 




S€INPUT#5,A$,X 

90 IF AS <> "Record Contents #" OR X <> R THEN STOP 
110 PRINT* IS, "B-F:" 0. T, S \ .^—v— ^ - ~v— ^ 

120 NEXT R f Checks To Miike 1 

l Sure Data Is OK/ 
130 CLOSE 4: CLOSE 5 V___^_ A _.. — / 

140 PRINT* 15, "S^KEYS" 
ISO CLOSE 15 

BUFFER-POINTER 

The buffer pointer keeps track of where the last piece of data was written. 
It also is the pointer fur where the riexi piece uf data is tu be ieid. By diang.n^ 
the buffer pointer's location within the buffer, you can get rar.duni access to the 
individual bytes within a block. Tills way, you can subdivice each block into 

records. 

For example, let's take a hypothetical mailing list. The information such as 
name, address, etc., will take up a total of 64 characters maximum. We could 
divide each block of ihe random access file into 4 separate records, and by 
knowing the track, sectoi, and record numbers, we can access that individual 
record. 

FORMAT FOR BUFFER-POINTER COMMAND: 

PRINT* file*. "BUFFER-POINTER:' 1 eriaiineljocation 
or abbreviated as 

PRINT* file*, "B-P"' channel, location 

EXAMPLE OF SETTING POINTER TO 64TH CHARACTER OF BUFFER: 

PRINT* 1 5. "B-P:" 5,64 

Here are versions of the random access wwiting and reading programs 
shown above, modified to work with records within blocks: 

SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS BLOCKS WITH 4 
RECORDS EACH: 

10OPEN 15,8,15 

20 OPEN 5. 8, 5. li # 

30 OPEN 4, 8, 4, ' KEYS.S.W" 

40 AS= "Record Contents #" 

iOFORK-1 IO 10 

feOFORL=l TO 4 

31 




■JO PRINT* ]5,"B-P:"5:(L-1)*64 ' ^^on to 0, (A. 1 28, or 192" 

80 PRINT* 5, AS ","L 

90 NEXT L 
10OT=l:S=l 

IJ0l»SINT#IS,"B-A."O;T;S 
120INPUT#15 : A, B$,C,D - 
130 IF A-65 THEN T=C: S=D: GOTO 110 
140 PRINT* 15 ; "B-W:" 5; 0; T; S 
IS0PRINT#4,T ","S 
1 60 NEXT R 
170 CLOSE 4. CLOSE 5: CLOSE 15 

SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS WITH 
4 RECORDS EACH: 

10OPEN 15,8,15 

20 OPEN S,8,5,"# 

30 OPEN 4, 8, 4, "KEYS&R" 

40FORR=1 TO 10 

50INPUT#4,T,S 

60 PRINT* 1 5, "BR:" 5; 0; T; S 

70FORL=1T0 4 

8QPRINT#15,"B-P:"5;(L-1)*64 

85 INPUT* S, AS, X 

90 IF ASO "Record Contents #" OR X=L THEN STOP 
1 00 NEXT L 

1I0PRINT#15,"B-F:"0;T;S 
120NFXTR 
130 CLOSE 4: CLOSES 
140 PRINT* 15, "SO KEYS" 
150 CLOSE 15 

USER1 and USER2 

The user commands are generally designed to work with machine language 
(see the next chapter for more on this). The USER1 and USER2 commands are 
Special versions of the BLOCK-READ and RI OCk'-WRITF commands, but . . 

32 



with an important difference: the way USER1 and USER2 work with the 
buffer-pointer. 

The BLOCK.- READ command reads up to 256 characters, but stops 
reading when the buffer-pointer stored with the block says that block is finished. 
The USER! command performs the BLOCK-READ operation, but first forces 
the pointer to 255 in order to read the emirs block of data from the disk. 

FORMAT LOR USCR] COMMAND: 

PRINT* file* "Ul : " channel, drive, track, block 
or 

PRINT* File* "UA:' 7 channel, drive, trsck, block 

There is no difference between the Ul arid UA designations for this 

command. 

The BLOCK-WRITE command writes the contents of the buffer to the 
block on the disk along with the value of the buffer-pointer. The USER2 
command wiites the buffer without disturbing the buffer-pointer value already 
Stored on that block of the diskette. This is useful when a hloct is to be read in 
with RI.OCK-RFAFJ, updated through the BUFFER-POINTER and PRINT* 
itatsments, and then written back to the diskette with USER2. 

FORMAT FOR USER2 COMMAND: 

PRINT* file*, "U2:" channel, drive, track, block 

PRINT* "ile#. "UB:" channel, drive, track, block 

For a more complex sample program, see appendix B, 



7. RELATIVE FILES 

Relative files allow you to easily zero in on exactly the piece of data that 
you want from the file, It is more convenient for data handling because it allows 
you to structure your files into records, and into fields within those records. 

The DOS keeps track of the tracks and sectors used, and even allows 
records to overlap from one block to the next, It is able to do this because it 
establishes side sectors, a series of pointers for the beginning of each record 
Each side sector can point to up to 120 lecords, and there may be 6 side sectors 
in a file. There can be up to 720 records in a file, and each record can be up to 
254 characters, so the file could be as large as the entire diskette. 



W 



33 



Creating a Relative File 

When a relative file is first to bs used, the OPEN statement will create that 
file; after that, that sam; file will be used. The replace option (with the sign) 
does not erase and recreate the file. The file can be expanded, read, and written 
into. 

FORMAT FOR THF OPEN STATEMENT TO CREATE RELATIVE FILE: 



OPEN file*, device*, channel*, "name, L," + CHRSfrecord length) 

EXAMPLES OF OPEN STATEMENT CREATING RELATIVE HLES: 

OPEN 2, 8, 2, "FILE.L.'H CHRS(IOO) *^ 

OPEN F, 8, F, A$+ ",L,"+ CHR$(Q> *■ t Record Length 

OPEN A, B, C,"TEST,L,"+CHRS(33) ^" 

Table 7,1 RELATIVE FILE FORMAT 



DATA BLOCK 


BYTE 


DEFINITION 


0.1 


Track and sector of next data block. 


2-256 


254 bytes of data. Empty records contain FF (all binary ones) 
in the first byte followed by 00 (binaiy all /.eius) tu the enc of 
the record. Partially filled records are padded with nulls (00). 


SIDE SECTOR BLOCK 


BYTE 


DEFINITION 


n,i 


Track and sector of next side sector block. 


7 


Side sector number. (0-5) 


3 


Record length. 


4,5 


Track and sector of first side sector (number 0) 


6,7 


Track and sector of seconc side sector (n timber 1 ) 


i$ 


Traekand sector of third side sector (nurrber 2) 


(i.i i 


Track and sector o f fourth side sector (number 3} 


12,13 


Track and sector of fifth side Sector (number 4) 


14,15 


Track and sector of sicth side sector (number 5) 


16-256 


Track and sector pointers to 1 20 data blocks. 



34 



Upon execution, the DOS fint checks to see if the file exists. If it does, 
then nothing happens. The only way to erase an old relative file is by using the 
SCR ATCHccmnanri (see chapter 4), hut not by using ihc replace option. 

Using Relative Files 

In order to OPEN a relative file once it exists, the format is simpler 

FORMAT FOR OPENING AN EXISTING RELATIVE FILE. 

OPEN file*, device*, channel #, ''name" 

!n this case, the DOS automatically knows that it is a relative file. This 
syntax, and the one shown in the above section, both allow either reading or 

writing to the file. 

In order to read cr write. you must, before any operation, position the file 
pointer 1o the correct record position. 

FORMAT FOR POSITION COMMAND: 

PRINT* file #. "P" CHRS(charm3l#)CtlRS(>e# lo)CHRS(roe#hi) 

or optionally as 

PRINT* file*. "P" CHRS(channel#) CHRS(rec#k>) CHRS(rec#hi) CHRI(pusilion) 

EXAMPLES OF POSITION COMMAND 

PRINT* 15, "P" CHRS(2)/CHRS(1) CHRSfO) 




PRINT* 1 5 , "P" CHRI(CH))CHRS(R 1 ) CHRS(R2) 
PRINT* 1 5, "P" CHRS(4) CHRS(R1 ) CHRS(R2) CHRS(P) 

The 2-byte format for the record number is needed because one byte can 
only hold 256 different numbers, and we car have over 700 reccrds in the file. 
The rec# In pnnrains the least significant part nf the address, and the rec#rii rs 
the most significant part. This could be translated to the actual record number 
by the formula REC# = REC HI * Z56 + REC LO. 

Let's assume we have a mailing list. The list consists of 3 pieces of data, 
according to this chart: 



F;eld Name 


Length 










state 


2 


first name 


12 


zip code 


9 


last name 


15 


phone number 


10 


address line 1 


20 
20 






address line 2 






city 


12 


TOTAL 


100 



35 



This is how the teeord length is determined. We would probably want to 
allow an extra eharacte' in length for each field, to allow for separations; 
otherwise the 1NPUT# command would pick up a much longer piece of the file 
than needed, just like in sequential files. Therefore, we'll set tip b file with a 
length of 105 characters per record. In the first record. wcTI put the number I, 
representing the largcs.; record* used 30 far. Here is the program as descjibed iu 
far: 

lOOPbN 1, 8, 15 

20 OPEN 2, 8,3, "0:MML1N(j LIS I ,L,' +CHRSi I OS) 

3(KiOSUB900 

40 PRINT* ; , "p" CHRSO) <CHR3(1) CHRS(O) CHRSl 1 1 

50COSUB900 

60 IF E=50 THEN PRINT#2. I : GOTO 40 

70 INPUT* 2, X 
300 STOP 

9001NPUT*!, K.BS.C.D 
9101F(E=50)OR<E< 20) THEN RETURN 
9 20 PRINT A;B: C; D: STOP: RFTIIRN 

Error #50 which U checked in line 60 of the program is the RECORD 
NOT PRESENT error, which means that the record hadn't been created yet. 
Writing into the record will solve the problem. This error condition must be 
watched carefuJy within /our programs. 

So far, all it docs is create the file and the first record, but doesn't actually 
put «ty data in it. Below is a gieatly expanded veision of the piogiam, tu 

actually allow you 10 work with a mailing list where the records ate coded by 

numbers. 

MAILING LIST READ AND WRITE PROGRAM; 

5 ,V(U= \2:M2) = 5; A(3] = :0:A(4) = J0:A(5)- 12: A(t)- 2: Ml}* 9:Mfi ' 10 

10 0PENl,8 1 15:OPEN2,M."0:MailiiieLisl,t,''*CHRS(l(l6):GOSLfB90(J 

20 FKIM*l,-'p , Q1K5(J^HI<ifltCHRSro)<;HR5i:i^INTUT»2.X 

30 iMPUT'Read, #ri;a, 01 End"'JS .1 FJS= VTHENCLOSE2 Cl-OSf. I :E«D 

40 |FJi="w"THEN2D0 

5C PRINT:[NFUT'R«:ord #':R:IF.* <0ORR>XTHENS3 

00 IFR<2THEN30 

70 RliR:R:=0:IFRIS.3S6TilEMP?=IMT(Bl, l l , ;ft)HT.t!l-3W"R2 

SO RESTOR£:DATI,F]BSTNAME.t4,LASTNAME,J0,A.I>DRESSI.;],ADDRESS: 

90 D AT A 72,CITY ,S5,ST AT £ .Bi ,Zl>\9S,PrlCW E # 

ICC FORL-ITOS RnADA,At:rElNT#l,' P '-CIlRSfl3)CllRHR!)CUKS(K2)CHRS(A)GO5UBTO0 

11C ONA/"ltlfi(ITtlS0JNPUT#2ZI:?R]NT\SiI:NEXT:GOTOS0 

20C PRIMTilNIitr'Rccmd #^R IFR<0OXR> 50OOT1IEN2M 

21C IFR<2TH™20 

215 IFR>-XIHE»tl-X*J PRINT .PRINr"Feeciid*"R 

23ft (tl=R:K2=fljlFR1>2SftTHFNR>1VT(RI,?'if;):RI=J(l -ISfcQJ 

230 RESTOREFORL^ITOS.READAJMPRtM*! . V'CHRSO) CHRJ(R: >CHRS(R2) CHRJ(A) 

240 PRINTAl:INFIJTZI:IFLEN(ZII>A{L)~niENZS*LEFTS(ZS.A(L)) 

245 l'RINT#2iS:NE>iT:X'n:Pfil>rT#],"p"CHRJ(3)CH1W(I)CIIRJ(:0} 

250 PRINT*1X:GOT0200 

900 INPLlT^l.A.BS.C,[);IFA<:()THENRtTURM 

Sit) IFAO 5BTHENPRJKT A;W,CfJ: STOP: RF1 URN 

?20 IFJ3="r"TKENPRJN7BS 

930 RETURN 

36 



This program asks for record numbers when retrieving records, h won't let 
you retrieve from beyond the end of the file, and if you try to write beyond the 
end it foxes you to write on the next higher record. 

A more advanced version than this would keep track of the items by 
"keys", to index the records. For example, you would probably want to search 
for a record by name, nr prirr nut labels by ?ip code. For this you would need a 
separate list o" kjys and record numbers, probably stored in sequential fil=s. 

When working with a r.ew relative file that will soon be very large, it will 
save much time to create a record at the projected end of the- file. In other 
words, if you expect the file to be 1000 records long, create a record* 1000 as 
soon as the file is. created. This will farce the DOS to create all intermediate, 
records, making later use o r those records much faster. 

EXAMPLE OF CREATING LARGE FILE. 

OPEN 1.8. 15: OPEN 2, 8. 2, "REL,L,"+ CHRS(60~I 
PRINT* 1. "P' : CHR5(2KHRS(0)CHRSf4)CHRS(l) 
PRINT* 2. "h'iND" 

CLOSE 2: CLOSE I """--— J RECORD* 4*256+0 

^OR 1024 

8. PROGRAMMING THE DISK CONTROLLER 

The expert programmer csn actually design routines that reside and 
operate on the disk controller. DOS routine; can be added that come from tie 
diskette. Routines can be added much the sane way as the DOS Support 
Program is 'wedged" into your memory. 

BLOCK-EXECUTE 

This command will load a block from the diskette containing a machine 
language routine, and begin executing it at location in tha buffet until a RTS 
fReTiirn from Subroutire) cfrnmflnrl is encountered. 

FORMAT FOR BLOCK. EXECUTE: 

PRINT* file*, "BLOCK-EXECUTE:" Dhannel, drive, track, block 

or abbreviated as 

PRINT* file*, "BLOCK-EXECUTE;" channel, drive, track, block 

MEMORY-READ 

1'here is 1 SK of ROM rn the d;sk drive as well as 2K of RAM. You can gel 
direct access to these, or to Tie buffers that the DOS has set up in the RAM, by 
using the MEMORY commands. MEMORY-READ allows you to select which 
byte to read, through the error channel. 

37 



FORMAT FOR MEMORY-READ: 

PRINT* file*, "M-R:" CHRS(low byte of address) CHR$(high byte) 
(no abbreviation!) 

The next byte lead using the GET* statement through channel* 15, the 
error channel, will be fruits thai ackhess in tlie disk tontrgllei's meiucny, ami 
successive bytes will be frum succes^ve memory lucaliyns. 

Any INPUT* to the error channel will give peculiar results when you're 
using this command. This can be cleared up ty any other command to the disk 
(besides a memory commsnd). 

PROGRAM TO READ THE DISK CONTROLLER'S MEMORY: 

10 OPEN 15,8, IS 

20 INPUT "LOCATION PLEASE"; A 

30 Al= INTC A/256): A2=A-Al*256 

40 PRINT* 15, "M-R:" CHR$(A2) CHRSCA 1 ) 

50FORL=1 TO 5 

60 GET* 15, AS 

70 PRINT ASC(AS+ CHRS(O)); 

SO MEXT 

90 INPUT "CONTINUE";AS 
100 IF LEFT$(A$,1) - 'Y" THEN SO 
110 GOTO 20 

MEMORY-WRITE 

The MEMORY-WRITE command allows yau to write up to 34 bytes at a 
time :nto the disk controller's memory. Tie MEMORY- EXECUTE and USER 
commands can be used to run this code, 

FORMAT FOR MEMORY-WRITE: 

PRINT* file*, "M-W: " CHRSflow address byte) CHRSlhigh address byte) 
#-of -characters; byte data 

PROGRAM TO WRITE A "RTS" TO DISK: 

1Q OPEN 15. 8. 15."M-W:"CHRS(Q)CHR$(5); 1:CHRS(96) 

20 PRINT* 1 5, "M-E:" CHRJ(O) CHRSfl 9): RFrVf JUMPS TO RYTF, RETURNS 

30 CLOSE IS 

MEMORY-EXECUTE 

Any i online in the DOS memory, RAM or ROM, can be executed with the 
MEMORY-EXECUTE command. 

38 



FORMAT FOR MFMORY-EXECL'TE: 

PRINT* Tile*, "M-E " CHRS(low address byte) CHR$(high byte) 

Sec line 20 above for an example. 

USER Commands 

Aside from the USER] and USER2 commands discussed in chapter 6, and 
the UI+- and Ul- commands :n chapter 2, ttie USER commands are jumps to a 
table of locations in the disk drive's RAM memory. 

USER COMMAND FUNCTION 

Ul or UA BLOCK-READ without changing buffer-pointer 

U2 or UB BLOCK-WRITE without changing buffer-pointer 

IB or UC jump to SO5O0 

U4 or UD jump to 10503 

U5 or UE jump to 10506 

06 or UF jump to $0509 

U7 or UC jump to J050C 

U8 or UH jump to S050F 

U9orUI jumpttt$FFFA 

U; or UJ power-up vector 

UI+ set Commodore 64 speed 

Ui- set VIC 20 speed 

By loading these locations with another -unp command, like JMP $0520, 
you can create longer routines that operate in the disk's memory along with an 
easy-to-use jump la We— even from BASIC! 

EXAMPLES OF USER COMMAMDS: 

PRINT* IS, "U3" 
PRINT* IS, "U"+ CHRS(5LH-Q) 
PRINT* 15, "Ul" 

9. CHANGING THE DISK DRIVE DEVICE NUMBER 

Software Method 

The device number is Selected by the drive by looking at a hardware 
jumper on the board and writing the number based on that jumper ir. a section 
of its RAM. Once operation is underway, it is easy to write over the previous 
devise number with a new one. 

FORMAT FOR CHANGING DEVICE NUMBER: 

39 



PRlNT#fi:e#,"M-W:" CHR$(l 19) CHRS(O) CHRS(2> CHR$(address+32) 
CHRI(addres5t64) 

EXAMPLE OF CHANGING DEVICE NUMBER: 



PRINT* 1 5, "M-W;" CHR$(i 19) CHRS(O) CHRS(2) CHR$(9+32) CHRS(9+64) 
FRiNT#Q, "M-W:" CHRS(119) CHR$(0) CHRS(2) CHR$(R-t32) CHR$(Rt64) 



If you have mors thsn one dr;ve, it's sensible to change the address 
through hardware (see below), [f you must, the procedure is easy. Just plug in 
the drives one at a time, and change their numbers to Ihe desired new values. 
Thai way you won't have any conflicts. 

Hardware Method 

It's an easy job to permanently change the device number of your drive for 
use in multiple drive systems. The tools needed is a phillips-hesd Scrawdriver and 

a knife. 

STEPS TO CHANCING DEVICE NUMBER ON HARDWARE: 

1 . Disconnect all cables from drhe, including power. 

2. Turn drive upside down en a flat, steady surface. 

3. Remove 4 screws holding drive box together. 

4. Carefully turn drive right side up ; and remove case top. 

5. Remove 7. screws on side of metal housing. 

6. Remov* housing. 

7. Locate device number jumpers, If facing the fron: of the drive, it's 
on the left edge in the middle of the board. 

8. Cut cither or both of jumpers I and 2. 

9. Replace housing and 2 screws, and case top and 4 screws. 
10. Re-connect cables and power up. 

The juniper number is added to die old device number (8) when cut. In 
other woids, jumpei 1 adds 1, and jumper 2 adds 2, to die device numbei. If 
none are cut, the number is S, if [ is cut it goes up lu9,and if only 2 IS cut die 
jtujnbei is 10. If both 1 and 2 are cut, the number is 11. 



40 



Appendix A: Disk Command Summary 
General Format: PRlNT#file#, command 



COMMAND 

NEW 

COPY 

NAME 

SCRATCH 

INITIALIZE 

VALIDATE 

DUPLICATE 

BLOCK-READ 

BLOCK-WRITE 

BLOCK-ALLOCATE 

BLOCK-FREE 

BUFFER-POINTER 

USER Land USER2 

POSITION 

BLOCK-EXEC LITE 

MEMORY-READ 

MEMORY-WRITE 

MEMORY-EXECUTE 
USER Commands 



COMMAND FORMAT 



"N 

"CO: newfik=0: original fife 

"RO.new name=0;old name 

"S0:flle name 

"I 

•*v 

not for single drives 

"B-R:" channel; drive; track; block 

"B-W:" channel; drive; trick; block 

"B-A:" drive; track; block 

"B-F;" drive; track; block 

"B-P:" channel; position 

"Un:" channel; drive; track; blnck 

"P" CHRS(channel#) CHRS(rec:# In) CHRS(rec# hi) 

CHRI(position) 

"B-E:" channel; drivs; track; block 

"M R:"CHRS(addressIo)CHR$(addrcsshi) 

"M-W:" CHRS(addrcsslo) CHRSladdress hi) CHRS 

(# chars) ''data" 

"M-E: " CHRS(address lo) CHRSCaddress hi) 

"Un:" 



41 



Appendix B: Summary of CBM Floppy Error Messages 

OK, no error exists. 

1 Files scratched response. Not an error condition. 
2-19 Unused error messages: should ba ignored. 

20 Block header not found on disk. 

21 Sync character not found. 

22 Data block not present, 

23 Checksum error in data, 

24 Byte decoding error. 

25 Writs-verify error, 

26 Attempt to write w:lh write protect On. 

27 Checksum error in header. 

28 Data extends into next block. 

29 Disk id mismatch. 

30 Geneial syntax enor. 

31 Invalid command. 

32 Long line. 

33 Invalid filename. 

34 No file given. 

39 Command Hie not found. 

50 Record not present. 

51 Overflow in recoid. 

52 File too large. 

60 File opal for write. 

61 Kile not open. 

62 File not found. 

63 File exists. 

64 File type mismatch. 

65 No Mock. 

66 Illegal track or sector 

67 Illegal system track or Sector. 

70 No channels available. 

71 Directory error. 

72 Disk full or directory full. 

73 Power up message, or write attempt with DOS Mismatch. 

74 Drive not i eady . (8050 only) 



42 



DESCRIPTION OF DOS ERROR MESSAGES 

NOTE: Error message numbers less than 20 should be ignored with the 
exception of 01 which gives information about the number of files scratched 
■villi iht SCRATCH command. 

20 READ ERROR (block header net found) 

The disk controller is unable to locate the header of the requested data 
block. Caused by an illegal sector number, ot the header has been 
destroyed. 

21 : READ ERROR (no sync character) 

The disk controller is unable to detect a sync mark on the desired track. 
Caused by misalignment of the read/write head, no diskette is present, or 
unformatted or improperly seated diskette. Can idso indicate a hardware 

failure. 

22, READ ERROR (data block not present) 

The disk controller has been requested to read or verify a data block that 
was not properly written. This error message occurs in conjunction with 
the BLOCK commands and indicates an illegal track and/or sector requast. 

23 : READ ERROR (checksum error in data block) 

This error message indicates :hst (here is an error in one or more of the 
data bytes. The data has been read into the DOS memory, but the 
checksum over the data is in eiror. This message may also indicate 

grounding problems. 

24: READ ERROR (byte decoding error) 

The dara or headar has been read into the DOS memory, but a hardware 
error has been created due to an invalid bit pattern in rhe data byte This 
message may also indicate grounding problems. 

25 ; WRITE ERROR (writ*- verify error) 

This message is generated if the controller detects a mismatch between the 
written data and the data in the DOS memory. 

26: WRITE PROTECT ON 

This message is generated when the controller has been requested to write 
a data block while die write protect switch is depressed. Typically, this is 
caused by using a diskette with a write protect tab omsi the notch. 

27: RhAD ERROR (checksum error in header) 

The controller has detected an error in the header or the requested data 
block. The block has not been read into the DOS memory. This message 
may also ;ndicate grounding problems. 



43 



28: WRITE ERROR (long data blo:k) 

The controller attempts to detect the sync mark, of the next header after 
writing a data block. If the syic mark does not appear withir. a 
pre-determined time, die error message is generated. The error Is caused by 
a bad diskette fornal (the data ex:ends into the next block), nr by 
hardware failure. 

29: DISK ID MISMATCH 

This message is generated when the controller has been lequested to access 
a diskette whicrt has not besn initialised. The message can alsc occur if I 
diskette has a bad header, 

30: SYNTAX ERROR (general syntax;) 

The DOS cannot interpret the command sent to the command channel. 
Typically, this is caused by an illegal number of file names, or patterns are 
illegally used For example, two file names may appear on the left side of 
the COPY command. 

31 : SYNTAX ERROR (invalid command) 

The DOS dees not recognize the command. The command must start in 
the first position. 

32: SYNTAX ERROR (long line) 

The command sent is longer than 5S characters. 

33: SYNTAX ERROR (invalid fde name) 

Pattern matching is invalidiy used in the OPEN or SAVE command. 

34: SYNTAX ERROR (no file given) 

The file name was left out of a commend or the DOS does not recognize il 
as such. Typically, a cohort (;) has been left out of the command. 

39: SYNTAX ERROR (invalid command) 

This etro; mty result if the command sent to command channel 
(secondary address 15) is unrecognizable by the DOS. 

SO: RECORD NOT PRESENT 

Result of disk reading past the last record through INPUT#, or GET* 
commands. This message will also occur after positioning tt> a record 
beyond end of file in a relative file. If the intent is to expand the file b\ 
adding the new record (with a PRINT* command), the arror message may 
be ignored. INPUT or GET shoulc not be attempted after this ermr is 
detected without first repositioning. 

SI : OVERFLOW IN RFCORD 

PRINT* statement exceeds record boundary. Information is truncated. 
Since the carriage return which is sent as a record terminator is counted in 
the record size, this message will occur if the total characters in the recoid 
(including the final carriage teturri) exceeds the defined size. 

44 



52: FILE TOO LARGE 

Record position within a relative file indicates that disk overflow will 
result. 

60: WRITE FILE OPEN 

This message is generated when a write file that lias not been dosed is 

being opened for reading, 

61: FILE NOT OPEN 

This message is generated when a file is heing accessed that has not been 
opened in the DOS. Sr>niet:mes, in this case, a message is not generated; 
the request is simply ignored. 

62: FILE NOT FOUND 

The requested file docs not exist on tht indicated drive. 

63: FILE EXISTS 

The file name of the file being created already exists on the diskette. 

64: FILE TYPE MISMATCH 

The file type does not match the file type in the directory entry for the 
requested file, 

| 
65: NO BLOCK 

This message occurs in conjunction with the B-A command. It indicates 

that the block to be allocated has been previously allocated. The 

parameters indicate the track and sector available with the next highest 

number If the parameters aTe «ro (0), filed all blocks highsr in number 

are in use. 

66: ILLEGAL TRACK AND SECTOR 

The DOS has attempted to acces; a trick or sector which doss not exist in 
the forma; beir.g used. This may indicate a problem reading the pointer to 
the next block. 

67; ILLEGAL SYSTEM T OR S 

This special error message indicates an illegal system track or sector. 

70: NO CHANNEL (available! 

The requested channel is not available, or all channels are in use, A 
maximum of five sequential files may be opened at one time to the DOS, 
Direct access channels may have six opened files. 

71: DIRECTORY ERROR 

The BAM does not match the internal count. There is a problem in the 
RAM allocation or the BAM has been overwritten in DOS memory. Tn 
correct this problem, reinitiate the diskette Jo restore the RAM in 
memory. Some active files may be termir.ated by the corrective action 
NOTE: BAM = Block Availability Map 

45 



72: DISK FULL 

Either the blocks on the diskette arc used or the directory is at its limit of 
152 entries for the 2040, 3040. and 4040 or 243 entries for the 3050. 
DISK FULL is sent when two blocks are available gn the 8050 Lo allow 
the current file to be closed. 

73: DOS MISMATCH (73, CBM DOS V2.5 8050) 
(73, CBM DOS V2) for 41)40 

DOS 1 and 2 are read compatible but not write compatible. Disks may be 
interchangeably read with e:ther DOS, but a disk formatted on one version 
cannot be written upon with the other version because the format is 
different. This error is displayed whenever an attempt is made to write 
upon a disk which has been formatted in a nrm-compatihle -"ormat. (A 
utility routine is available to assist in converting from one format to 
another.) This message miy also appear after power up. 

74: DRIVE NOT READY 

An attempt bes been made to access the SO50 Dual Drive Floppy Disk 
without any diskettes present in either drive. 



46 



APPENDIX C: Demonstration Disk Programs 

1. DIR 



<* 0*-EN2jS, 13 

5 P?IMT"3" :GOTO 10903 

10 ?PEHI.,S J J "*0" 

23 GET#l,RS,B3 

3S 0ET#ljfW,B$ 

53 C=C 

59 If RfO*" THEN C=flSC(FiS) 

7B IF ESC"" THEN C=C+HSCCES 5*256 

93 PR IN"" B"Mirj!f <STK*<C^Z>.iTnB(3S. "g"j 

90 ge-*!,!!*:^ stog then ]aee 

100 IF BSOCHR$<34> THEN 96 

110 GETtl.EJUF 5*<>ChffiSK3*JTHEN PRINTS*; fQOTCIifl 

12B OET«i,B*=IF E*»CHR*C32J THEN 128 

13E PRINT TRBijaS ;;£*«*" 

140 C*=C*+B*:QET#1.B*:1f B*0" " THEM 1^0 

151 F'RIHT"S"LEFr*<;CS..3) 

16© BET T5*:IF T*0"" THEN (jQSUB 2030 

176 IF ST=0 THEN :30 

10BB PRINT" BLOCKS FREE" 

1S19 CLOSEl^SOTO 10000 

2000 IF T$="«" THEM- CLOSE! J EtfQ 

2(510 GET T*:IF T*="" THEN 280E 

2(520 RETURN 

4C60 REM BISK COMMUNE 

4818 C*n PRINT ■'>■; 

4911 CETB*- IF£i*-"" THEN4SH 

4012 PRINTS*; :IF BS«CHR*<13i THEN 4020 

4013 C*=C*+B*:QOT0 4611 
4UiiO FRINT#2jC* 

ssee print"*' j 

3£l<3 GET*?, lil* I PPTWTRrt ; : IF RSOCHP*^ 131GOTC1S010 

5G2G FRINT"»» 

1BS00 PRINT "D-TJIRECTORY" 

1001a print ">-jji5k coMHflNB" 

190 PR PR TNT "G -Gil IT PRQGRftlt" 

ieese print "s-disk status " 

10100 GETflf : IFfi*-'" : TFEH10108 

isaes if ft*-= r D" then 10 

18300 IF ft**".' OR R*=">" 03 !!*«">« THEN 43G3 
10310 IF R?- r Q» THEN END 
10320 IF fl$='S" THEN 5933 
16P5S 0QTD 101B0 



2. VIEW BAM 



103 REM Ka^lff*^*^****** 1 !***************** 

131 REM * VIEW EHM FOR VIC & 64 BISK * 

102 S:E''' ****#*^* ************* *********** 

105 0PEN1S.8. 13 

118 PRINT* [3. "10" :NU*="-4/fl N/fi N^fl H-fl Nr i fl , -E4-1 

130 V* - " OWITMKWIJWra WftJlIJlMflMiMWM! ' ' 

149 ^"FMMkMHlrtiftMMCMMd" 

15D DEF FN5C2J = 2TC5-IMT;S/5:.*S> FIND t%KWT<$/8))} 



47 



169 PRIHT#15,"U1 :";2;3;lS:S 
179 PR1NTIH5»"]S~P"j2j1 
isa pftiHT"a" i 

S0@ FORI=0TO20 : PRIMT^RIhr"TT'Rir5HT*irSTR*fI>l-" ",3):;NE>CT 
213 GET#2,PW 

33@ G£T*2.. tf* 

£45 TS=3 

£5S FOFT=1TO17-GCSUE450 

269 Y=22 : K= r+4 : G0SUE433- G0SUB54G I NEXT 

27C FClRI = lTOaa£-B=)JS<!T:Pa!NT":j" 

2B9 V=2 2 : X= 1 : BOS UTS 430 

2?0 FOR! I-OTOSB SPRINT -^IMT-TTRIGHTSCSTR* a 3 + " "..Sttj-iHEKT 

330 FQRT>1STQ33 

313 9Q3US430 

330 fori =i to 1000= next 

346 PR:HT"3SWi!W 

336 PRINT* 15. *B-F" ; z; 144 

3£9 M*-=" " - FOfer-lTOES : GEITKE ,, n* - N*»N**PW ■ NiXT 

37fl PRINT" "N*" "TS-l'J 'BLOCKS FREE" 

338 fQRI=lTO4090-HE^T 

330 PRINT"?!" 

490 tHPUT")IWM»FHOTHEF: DISKETTE HIM]" i R* 

41fl TFftS= llp J"THEHRJH 

4SB rFft*O n ¥"THEMEN3 

43S PRlNTLEFT*< 1 l , *.V>LET*T*?Sf,X5 n II"J 

44 El RETURN 

4"5£1 GETMS r SC*:S:=^SC<RIiSHT*'f:HR* l ;B)+3C* J 1>J 

4S0 TS=TS+SC 

470 GETtts.. R*: IFR*=" "THEHFW-CHR*<0:i 

496 GET#2.. R*: IFR*=" "THEilR^ITHRirW 

508 SEdS^RSCCfWi 

510 G6T*2,P»; IFft*= ,IIT THEHfW=CHR*<e3 

530 RETURN 

540 PRJNT"MU"ftISHT*tSTR*i:Y}..lijl "im": 

553 P£V PRINTT" "££" "SE^SV l! SEC 1 > " »SB(a)=CHR*<33 

5S0 3FT>24flHD3=LSTHEN:PRINTMIE*i;NlJ?i.iZ4, 1>; :i5CTO6S0 

r>70 FOR3*at023 

580 IPKISTHEMSB8 

59B JFT>39nHBS-'l?THEN : PRINTPilD*(NU* J 24i 1 ) i ^OOTcsee 

503 IFT>24H4DS = lSTHEN:PRIt-TririD*fi)U* J Z4. 1); : GOTCSE0 

616 IfT>24flNr&=lS l THEMFRlHTn3D* l ;N'J*.<:4j 1 .1 i ; IjOTDgSe 

620 IFT>t7 , fHBS=2STHENPRIM7MID*<;HJ*.Z4, : J .! - 24*24-1 1 : GQT06OT 

eae print" »■; 

640 rF PN5CS>«0 THEN PRINT"-!" .: : eOT0669 

COS PMHT'ef U-REflRlBHTSC.STR^S'', 1J :Z4" i; i -C n T072 
£G3 FRIHT'TIH'; 
£70 SEXT 
S3S RETURN 



3. DISPLAY T&S 



i $e rem*********w******************** 

iJB REM* EISPLfi-' flNV TRACK * SEC'Ofi * 
JS8 REM* OH THE BISK TO THE SCREEN * 
130 REM* OR THE PRINTER * 

350 PRINT" IHM . " 

I'5G PRINT" DISPLAY ELDCK CONTENTS " 
I 65 PRINT" ' : 

ioe REM* SET PRoep.nr constant * 
l4fj RFn*****#********iW*tf************ 

see sp*=" l| :ML*=CHP*(:0:'■^:>;*- l el^54ES7^3inE;DEF , 

210 FS*= F0fii=6'l TO 35iFJ$=F;;S+ ,, a ,, +CHR*i;I> + "a" :NE>;T I 

£2S S5S-=" "FOP 1=152 TO 223-S.S*=SS*+"8" + CHR*<;i >i-"S" NEJ<T I 

24(3 DIM WClSJ.HEOi 

£51 B*="0" 

553 PRINT" SBBCREEMS11BH1BWDR MISFBRIHTER" 

354 OETJJSMI- JJ$="" TH5NK34 

PES IF JJ*^"S»THEMFRINT" WSKChEEMS" 

£56 IF JJ*="F"THE>PRINT" M8FRINTERB" 

££B 0PEH15,S,15.. " I"+II*- GCiSUE 650 

£65 I3PEK4.4 

£70 OPEH 2,0,5, "«" 'ODSUB C5B 

280 R£M***************ti*******i**#**** 

£93 REM* LOAD TRRtK FIND SECTOR * 

3013 REIW rH"D DISK BUFFER: # 

32J1 HPIJT 'tMfTRPfiK. SFCTGR-i;~,S 

330 r r T = 9 OR T535 THEN PR [N"4t 15," I"IW : CLI3SE2: CL0SE4 ■ CL03EL5 FPIMT"ENTJ" I END 

340 IF JJ*="S' THEN PPINT":airrPfiCK"T" SECTOR "g"W" 

541 IF JJ*-"P- THEN PRIHT#4 ; F'P.1NT»4,. -'TRACK: "T" SECTOR'S : FP-I NT*4 

353 PUINT#1S.. »U1 !2, "D¥ITIS:COSUB£50 

3S0 REn******3****l*****************i*** 

"170 REM* KEfiE E'tTE OF DISK BUFFER * 

390 REM*******#***#****#**#****#3t*#** 

■iaa PRinTtis, "B-p^a-i " 

419 PRINT#15> "M-R"CHR*C0>CHR*C5J 

426 0ET*1S> R»<8> = H r Fi*<e>=""TH&B*<9>«=NL* 

428 IF »TJ*» -, S i 'THEH4S« 
459 IF J , J , s^'P"THEM463 

431 REM******************************- 

432 REM* READ & CRT DISPLRV * 
4:« R£(1i>i KE5T OF THE DISK SUFFER * 

434 REM****************^*** 1 **^* 5 !^***** 

435 K=l NKl>=f*9C<:ft*C0no 

433 FOR J=9 TO 53: IF -J=3E "HEN SOStffi /IfPiF 2*="N"TH5H ,T=S9 i GOTO 459 
440 FOR I*K 10 J 

442 GET#2,FW<;I> -IF fl*a?= N " THEN fl*CI>e>NL* 

444 IF K=l AND IC2 THEN NB<2i«fiSC<ifl*< [» 

445 NEXT I-K=B 

448 fftte*' u IS*= II t"JW«J**:0OSUB ?S« :fW=FI*+» i 1 
450 FOR 1-0 TO 3iN-flSC<fl*<:i}>;G0SUS 730 

454 fJEKT I: IF JJ*="S" THEM PRINTFWES 
458 NEWT J-COTDSn 



49 



460 REM****************************** 
4S2 REM* READ * PRINTER LISPLflV * 

46£ K«l : tJE<l>=fiSCiTFl*0>5 

468 FOR 1=8 TC 15 

47* FOR 1=K TO 15 

472 GET#2,H*<:i> : IF «*< I ■>■="" THEN Md^NL* 

474 IF K=l RNE K2 THEIJ WB(2^=PSCf H*(I S > 

476 NEHT I : k~S 

478 Rt="":B5=": ":N=Jtl6-G0SUB 790:fW»3S+ 

4a® p^f* 1-6 to i3-N=Pisc<:n*<;i:''p gosub 799: if 2*»"W"THEN J*40-bo~d 571 

4S2 C**fl*CI>'OOSUa S50-B*=i*+c* 

484 NEXT I 

436 I c JJ*='P" THEN PRINT*4.Pi*E* 

485 NEXT J. OOTK? 1 

ZT 1 R^M***:*************************** 

372 R=M+ NEXT TRACK AMD SECTOR * 

"573 F iM*** ******* ***f **+**.* +*v:f* 4?* *■** 

E75 P^INT-NEKT TRACK RND SECTOR"NBa 3NBC2) "M" 

5B0 FRINT"DO YOU WANT NEXT TRHCK FfND SECTOR" 

590 OCT Z*:jr s*-"" THEN59Q 

600 IF 2*="V" THEM T=MBC 1} ' S=N1<2> -GDTO330 

SI 9 IF Z*-"N" THEN 320 

S£0 OUTO 330 

■>'■'■'■ F:£H********** ******************** 

643 REM* SUBROUTINES * 

■s50 REM****************************** 

S63 REM* ERROR ROUT ME * 

i578 REM*********************)!******** 

■SSB IHPUT#15 J £N..EH*,ET.ES'1F EN=3 THEN RETURN 

£90 PRINT 11 SEISK ERROR" 'EN, EM*, ET,ES 

709 ENE 

71 REM****************************** 
72S REM* SCREEN CONTINUE MESSAGE * 
7:90 RGMw***************************** 
74PI PRINT' HMKMCONTIHUE^-V'N;'" 

750 OET^*:lF Z*=" " THEN 750 

750 IF Z*i="N" THEN RETURN 

770 IF 3SO"V" THEM 750 

7S0 PRINT' nrRfCK" T " SECTOR"S "3" : RETURN 

790 REM****************************** 

800 REM* DI£K E'tTE TO HEX PRINT * 

S1I0 REM****************************** 

22B RisimyN/'i.Gi ;fl*=fl*+M:D«cnw*,ni+i , ii 

S4S R±=R*+SP*:RETU*N 

H58 REI1*****************«************ 

9SQ REM* DISK BVTE TO RSC DISPLAY * 

S76 REN* CHARACTER * 

P30 R£ri*****+**i*f**#***l**************** 

890 IF RStXC*K32 THEN C$=" "'RETURN 

91.8 IF RSCtC*><lE9 OR fi5C<C*:>>155 THEH RETURN 

920 C.i=M ! r« i.' RS*,?!*(fiSb _ :fi"S , >- 157^,^5 : RETURN 



50 



4. CHECK DISK 



1 REM CHECK DISK — VER 1.4 

S DH»8:REI1 FLCPF U DEVICE NUMBER 

5 DiMTaee) -DiHsaees ; REM ehd tfshckj sector rr^rv 

9 PRINT":ftWIfl~— — " 

] .-I Fpr-JT" C:HEr:l' DISK PROGPRM u 

12 PRINT" *"" " 

29 M»"g" 

3C OPEN 15, UN, 13 

35 PRINT#15,"V"D* 

45 HK-RHD<Tl5i*2SS 

5 g H**" " : F0RI=1T0253 :B^=H*+CHR*C255ftHD t I+t~K>> 'HEp^T 

68 oosuBsee 

76 OPENS j EN >£."*" 

86 PR3HT;PF?THT*?,FI5; 

55 T=1-S=0 

98 PRIHT#15,"E-F|: "B*JT;S 

IBS IHPUT*tlS.eS,EM*jETjES 

1:0 IFENhBTHEHISB 

1:5 IFET=CTHEN26B:REI1 EHD 

120 PRINTS 15, ,, E-fl: "D*.:ETj££:T=ET:S=ES 

ise PMH"rtfl3.?*'U2'£i "W*TJS 

134 NB=NB+1 : PRINT" CHECKEE ELOCKS"MB 

135 PRINT" TRACK liMH"T;" SECTOR MWHI'-S'TTT 1 
149 IHPIJTHIS.EH.. EW#,ES,£T 

158 IF EH=0THEN83 

16H PRINT"MMEflD BLOCK : 111" j TjS"" 

1*6 G0T0S5 

208 PRINT*15, "I"0* 

3 to oosusseo 

212 CL0SE2 

215 IFJ=0THENPRINT J KBB*1HNO IRD BLOCKS I" ; EW 

217 OPENS, DN. 2.. "»" 

2115 FF.INT"M»flSRI> BLOCKS" , "TftflCK" , "SECTOR* 

22G FCiRI^QTO.r-1 

230 PPINT*15j "B-B- ".;D*.T< I3;SfI3 

248 PRlHT>,T«I>jSCn 

250 NEXT 

56fi Pf:INT , 'W"J"BRB BLOCKS HAVE EESJ RLLflHRTFTi" 

2-f CLONES: END 

380 INPUTSlS.HJ.ENf/ET.ES 

SIB IF EN=0 THEN RETURN 

9£6 F'P.tNT' WKERROP #"EH. EH*;ET;£S"" 

930 FEINT*1"VI"D* 



5. PERFORMANCE TEST 



isaa FEn performance test 2.e 

1019 ■■ 

1^20 BFH yiC-?R fi'lTl nriMMIIIIOPE 64 

1030 REN SINGLE FLDPPV 31 SK DRIVE 

1943 : 

1053 OPEN IjSj t3:0FEH13..$, :5 

low LT-35 

1073 LT**STR*HLT> 



51 



PRINT 

PRINT" 
PRINT 

PRINT" 

PRINT 

PR I NT "IS 

PRINT 

PRINT" 1JHEN RESIiVW" 

FOR 1=0 TO 50 : OET P*"HEKT 

GET 1=13. IF fl*OCHR3K13> THEM li 



11-1^.1 NT =38 

ti»TO p(*lMT"TMk- 

ki«B PRIMT" 
1110 PV1NT" — 



1120 

11.36 
1 140 

i isa 

1160 

i ire 

use 

I 198 

I 2fl0 
1210 

[230 
1240 
1 253 
1. 263 
1.270 
1230 
l:---,fi 
1.3S9 
1310 
I 320 
1330 
I -:4-i 
1350 

inse 

1 378 
13B0 

1390 
1408 

1419 
1.420 

1430 
1440 
1450 

use 

1470 
14B0 
14SQ 
1300 
1510 
1520 
1559 
1540 
1550 
l^SB 
1370 
1560 
1590 

isea 

1610 

less 

1630 
1640 
1650 

isse 



PERFORWMCE TEST 



INSEK1 SCRATCH" 



■DISKETTE IN IRIVE" 



F'RESS BFETURH"" 



111 



TI*h"800908" 

TT=1S 

PRINTS], ," HO: TEST BISKj 00" 

Cl*=" DISK NEW CCMMflND "+CHft#<133 

C2*="M HRIT ABOUT £0 SECONDS " 

CC*"CI**C2*:©0SUI 1S40 

IF TKHTTHEW1370 

PRINT"M5VSTEn IS" 

PR I NT "W WOT RESPOHBIMG" 

PRINT" CORRECTLY TC COM^RKBS " 

DDSUB 1SS0 



PR J NT "BOB I VE PfiSS" 

PRINT" MECHRMCAL TESTS" 

TT^Il 

OPEN Z,3,Z, "B'TEST FILE.. 3, W" 

CC*="0PE<1 WRITE FILE" 

CH=£:CC*="HR.:TE TJHTH" 

CC*"" CLOSE "-i-CC* 

OPEN £.8j2. "8 -TEST FILE.. S,R 

CC*="OPEH RE fiB FILE" 

C.H=S:G0SJ8 1390 

PRINT«,"S0--EST FILE" 

CC*»"SCRflTCH F1LEJS":TT=1 



on siit 1S49 
S0SU1 1930 
GOSUB 1948 



GOSUE 15140 



GOSUB 1840 



TT=21 

OPEN 4,Sj4i "#" 

NNK-<l + pyD(TI>^254+HN?i;'FiHD2S5 , P! : ;IKT#l,. "S-P"J4, 

NN*= FDR 1 = 1 TO 255: NUS=NW*+rHP3( n NE*:T 

PRINT* 4.HM»J 

PRINT* 1, "IJ2 : ";4;0:LT;Q 

CC*="WRITE TRACK' +LT* ■ 003UB 1848 

PR I NTS 1," US- »;4;0J i;B 

CCS="WRITE TRACK 1" : GOSUE 1849 

PRINTS1,"LII : " .: 4.: 9J LT;0 

CC*="REFID TRUCK" +LT3 ! OOSUE 1S40 

PRINT#1, "Ul ! ";4;B; 1 ;B 

CCS="READ TRfiCK 1" ! GQSUB 1840 

CLOSE 4 



MMK 



52 



1S7S PRINT"* UNIT HAS PASSED" 
IfiSP PRINT" PERFORMANCE TEST'" 

169E F'RINT"SJ PULL B3SKETTE FROM" 
1706 PRINT'M DRIVE BEFORE TURNING" 
1710 PSLVT POWER OFF." 
1723 Ertti 

1733 : 

174e : 

1756 PRINT" SKI3NHMJE CY/-VJ ?■■ , 

1760 FOR 1=0 TO 50 -GET FWWEXT 
1770 GET fit .IF Ftt»"" THEN 1776 
173C PRINT R*"M" 
i?90 I r W« B W" THEN 1 END 

1680 i- fl*»" v " THEN RETJR4 

keta GDTQ I7«e 

1S20 i 

1833 : 

1S40 PRINT CC$ 

1S50 INP.JT* 1,EN..EI"!*-ET,EB 

1660 PBIWTTaB(12V ll 'EHjEM*;ET;ESJ "■' 

1579 IF en;2 them return 

18B0 PRINT"]* UNIT IS FHILINB" 

1590 F'R1HT"W PERFORMANCE TEST" 

1=R65 TM#nTfi:finSllI! 1 750 : TI*«TM* : RETLRH 

isie : 

1=20 : 

1530 PRINT"WRITINQ DRTR" 

194B FOR I-1BBG TO 2000: ppiWTdCW , 1 - WEVT 

1550 GOSUB 1.650 

ISfiS CLOSE CH: RETURN 

1970 i 

19SS : 

1990 PR1HT"REB3IH0 DATA" 

20pg GETfl* 

2010 FOR I=1B«0 TO i!BBB 

S(53« INPUT* CH.J 

2GM IF J<> I THFH PRINT" BSEM) ERROR :B" i OOSUB 1.853 

3046 NEXT 

205B 60SUB 1950 

2(568 CLOSE GH : RETURN 



53 



APPENDIX D: DISK FORMATS 




OLLCK. 
SUM 



POINTERS TO LINK 
TOGETHER ALL 3LQCK! 
WITHIN AiUI 



NOTE 
Not to scale 



\ 



254flVTtS 
01 BATA 



CI ICC K- 



1540/1541 Format: Expanded View of a Single Sector 



54 



Block Distribution by Track 



2040, 3040 


Block or 




Track number 


Sector Range 


Total 


I to 17 


0:o20 


21 


1 3 to 24 


0:o 19 


20 


25 to 30 


0:ol7 


18 


31 to 25 


0tol6 


17 


4040 


Block or 




Track ninnher 


Sector Range 


Total 


1 to J 7 


0;o20 


21 


1 8 to 24 


to 1 8 


19 


25 to 30 


0:ol7 


18 


31 to 35 


to 1 6 


17 


805Q 


Block or 




Track, number 


Sector Range 


Total 


1 to 33 


:o 28 


29 


40 to 53 


to 26 


27 


54 to 64 


Oto24 


25 


65 to 77 


to 22 


23 



1540/1541 BAM FORMAT 



Track 18, Sector 0. 


BYTE 


CONTENTS 


DEFINITION 


0.1 


18,01 


Track and ssctor of first directory block. 


2 


65 


ASCII character A indicating 4040 format. 


3 





Null flag for future DOS use. 


4-143 




Rit map of available blocks for track.? 1 -35. 


* I - available block 
0= bloc knot available 

(each bit represents one block) 



S5 



' STRUCTURE OF SINGLE DIRECTORY ENTRY 



BYTE 


CONTENTS 


DEFINITION 


U 


128+type 


File type OR'eri with SSO to indicate properly 

closed file. 

TYPES: G = DELeted 

J = SEQential 

2 = PROGram 

3= USER 

4= RELative 


1-2 




Track and sector of 1st data block. 


3-18 




File name padded with shifted spaces. 


1 9-20 




Relative file only: track and sector for first $ide 
sector block. 


21 




Relative file only: Record size. 


22-25 




Unused, 


26-27 




Track and sector of replacement file when OPEN!" 
is in effect. 


25-29 




Number of blocks in file: low byte, high byte. 



SEQUENTIAL FORMAT 



BYTE 


DFFINITION 


0-1 


Track and sector of next sequential data block. 


2-256 


254 bytes of data with carriage return as record terminators 



PROGRAM FILE FORMAT 



BYTE 


DEFINITION 


0,1 


Track and sector of nex: block in program file. 


2-2S6 


254 bytes of program info stored in CBM memory format (with 
key words tokenized). End of Tile is marked by three zero bytes. 



56 



1540/1541 DIRECTORY HEADER 



Track 18, Sector 0. 


BYTE 


CONTENTS 


DEFINITION 


144-161 




Disk name pat (led with shifted spaces. 


162-163 




Disk ID. 


164 


1&0 


Shifted space. 


165-166 


50,65 


ASCII representation for 2A which is DOS 

version and format type. 


166-167 


160 


S. lifted spates. 


177-355 





Nulls, not used- 


Note: ASCII characters may appear in locations 180 thru 191 on some diskettes. 



DIRECTORY FORMAT 



Track 18, Sector 1 


BYTE 


DEFINITION 


0-1 


Track and ssctor of next directory block. 


2-51 


*File entry 1 


34-63 


*File entry 2 


66-95 


*File entry 3 


98-127 


*File entry 4 


130-159 


*FiIe entry 5 


162-191 


*FLte entry 6 


194-123 


*File entry 7 


226 255 


*FiJe entry 8 



57 



RELATIVE FILE FORMAT 



DATA BLOCK 


BYTE 


DEFINITION 


0,1 


Track and sector ol n^xt data block. 


2-256 


254 bytes of data . Fmpiy records contain FF (all binary ones) in 
the first byte followed by 00 (binary all zeros) to the end of the 
record. Partially filled records are padded with nulls (00). 


SIDE SECTOR BLOCK 


BYTE 


DEFINITION 


0-1 


Track and sector of next side sector block. 


2 


Side sector number (0-5) 


3 


Retoid length 


4-5 


Track and sector of first side sector (number 0) 


6-7 


Track and sector of second side sector (number 1) 


8-9 


Track and sector of third side sectOT (number 2) 


10-11 


Track and sector of fourth side sector (number 3) 


12-13 


Track and sector of fifth side sector (number 4) 


14-15 


Track and sector of sixth side secrnr (nurrher 5) 


16-256 


Track and sector pointers to 12D data blocks 



58 



VIC-1541 User's Manual Errata Sheet. 



INTRODUCTION 

Commodore is constantly trying to bring you the most efficient and reliable 
computer in the world today. Along with the hardware improvements that come 
from practical applications of the 1541 disk drive in the marketplace, the docu- 
mentation should also retlect any changes and/or improvements that occur. 
This is the most up-to-date information available for your 1541 disk drive. The 
changes listed here should be used ta replace tlie comparable information in 
your User's Manual. Future updates will normally be available through the 
Commodore User's Magazines (COMMODORE and POWER PLAY) as well as 
the COMMODORE INFORMATION NETWORK on CompuServe. 

The format of this upda 7 .e is as follows: 

A. 1. Page and Paragraph or Section of the VIC-1541 User's Guide. 
2. Old infbrmaliun. 
3 Ne w information. 

Example; 

A. 1. P.3, INTRODUCTION, paragraph; 

2. ... use your Commander 64 or V]C 20 User's Guides . . . 

3. ... use your Commodore 64 or VIC 20 User's Guides . . . 

The following listing is performed in numerical order by page. 

A. 1 P. 3 , INTRODUCTION, paragraph S 

2, ... use your Commander 64 or VIC 20 User's Guides . . . 

3. ... use your Commodore 64 or VIC 20 User's Guides . . . 

B. 1, P. 4, SPECIFICATIONS, paragraph 2, line 6 

2. The "pipeline" makes the disk abot to process commands . . . 

3. The "pipeline" makes the disk able to process commands . . . 

C. 1. P. 7, CONNECTION OF CABLES, paragraph 3, line 3 

2, ... at one time, read chapter K . . . 

3. ... at one time, read chapter 9 . . . 



D. 1. 
2. 
3. 

E. I. 

2. 
3. 

F. 1. 

2. 
3. 

G. 1. 

2. 
3. 

II. 1. 



K. 1. 



P. 9, USING WITH A VIC 20 OR COMMODORE 64, last paragraph 
. . .explanation of the U(i:ser) commands in chapter 7 
. . . explanation of the U (user) commands in chapter 8. 

P. 10, EXAMPLES, example 3 
LOAD AS, J K 
LOAD A$, J, K 

P. 13, FORMAT FOR THE SAVE COMMAND, fust paragiapli, line 1 
See the LOAD command (pages &, ) for an explanation . . . 
See the LOAD command (page 10) for an explanation , . . 

P. 13, FORMAT FOR SAVE WITH REPLACE:, example 
SAVE "=0:" +name$, device*, command* 
SAVE "@0: '' + namet, device #, command* 

P. 14, FORMAT FOR THE OPEN STATEMENT:, example 
OPEN file*, device*, (command) channel*, text S 
OPEN file*, device*, channel*, text $ 

P. 1 5 , paragraph, aftsr EXAMPLES OF OPEN STATEMENTS:, line 4 
, , . the disk drive, which LOADs it onto the diskette. 
. . . the disk drive, from which it goes to the diskette, 

P. 19, CLOSE NOTE: (paragraph 3 on p. 19), line 4 
CLOSE 15: OPEN 15,8, 15: CLOSE 15. 
OPEN 15,8, 15, "I". 

P. 20, EXAMPLES OF OPENING SEQUENTIAL FILES: 
OPEN 2, 8, 2, "ODATA, S, W" 
OPEN 2, 8,2, iL 0:DATA, S.W" 

P. 20, EXAMPLES OF OPENING SEQUENTIAL FILES: 
OPEN 8, 8, 8, "OProgram, P, R" 
OPEN 8, 8, 8, "0:PROGRAM, P, R" 



M. 1 , P. 23 , READING THE DIRECTORY, sample program, line 1 

2. 10 OPEN 1,8, 2, "S 

3. 10 OPEN 1,8,2, '% 

N. 1, P. 24, TABLES, 1, line 4-143 

2. 4-143 Bit map of available blocks for trace 1-35 

3. 4-143 * Bit map of available blocks for trace 1-35 

O. 1. P. 27, TABLE TOP OF PAGE 27 
2. 
3. Tsble 6. 1 TRACK AND BLOCK FORMAT 

P. LP, 30, SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS . 
lines 40, 90, 100, 120,130, 140 

2. 40 AS- 'Record Contents #" 
90 T=l : S=l 

100 PRINT# 15, "B-A:" 0,T, S 

120 IF A=6S THEN T=C: S=D: GOTO 100 

130 PRINT* 15, "B-W: " 5, 0, T, S 

140PRINT*4,T","S 

3. 40 A$=" RECORD CONTENTS #" 
90T=1:B=1 

1 00 PRINT* 15, " B-A: " 0, T, B 

120 IF A=65 THEN T=C; B=D: GOTO 100 

130PRINT#15."B-W:"5,0.T,B 
140PRINT#4, T;B 

Q. I. P. 3 1-32 SAMPLE PROGRAM WRITING 10 RANDOM- 
ACCESS..., lines 40. 100,110,130, 140,150 

2. 40 AI="Recorcl Contents #" 
100 T=l : S=l 

1 10 PRINT* 15, "B-A; " ;T;S 

130 IF A-65 THEN T=C : S=D: GOTO 1 10 

140 PRINT* IS, "B-W: " 5, 0, T; S 

: 50 PRINT* 4, T","S 

3. 40 A$="RECORD CONTENTS #" 
100 TM : B=l 

1 10 PRINT* 15, "B-A:" 0;T; B 
230IFA=65THENT=C: B=D : GOTO TO 
140 PRINT* 15, "B-W:" 5;0;T; B 
150 PR INT* 4, T;B 



R. 1 . P. 41 , APPENDIX A : DISK COMMAND SUMMARY, line 3 

2. NAME "RD: new name . . . 

3 . RENAME " RO : ne w name . . . 

S. 1. P. 46, 72: DISK FULL, lines ?_-3 

2. ... 152 entries for the 2040, 304C, and 4040 ar 243 entries for trie 
8050 .... when two blocks are available on the 8050 to . . , 

3. , . . 144 entries for the 1541 .... when two blocks are available on 
the 1541 to . . . 

T. LP, 46, 73: DOS MISMATCH, title line 

2. DOS MISMATCH (73, CBM DOS V2,5 S050) 

(73, CBM DOS V2) for 4040 

3. DOS MISMATCH (73, CBM DOS V2.6 1 541) 

U. LP. 46, 74: DRIVE NOT READY, line 3 

2. An attempt has been made to access the 8050 Dual Drive Floppy Disk 

3. An attempt has been made access the 1541 Single Drive . . .